Issue
I need to validate a text input so a user can insert characters/text that may include German umlauts, French accents and any other valid European characters, for example the minuscule ø.
I am using AngularJS so I am applying my validation rule to the ng-pattern
attribute like so:
ng-pattern="/^[A-Za-z0-9 \-_.]*$/"
I was hoping this would cover characters like äöüß but when testing it doesn't. Sorry to ask such a lame question but I am really bad at RegEx! There must be a better way than manually listing the letters like so ng-pattern="/^[A-Za-z0-9äöüÄÖÜ \-_.]*$/"
Solution
Javascript regexes don't support unicode properties, the only way to include non-latin letters is to list them explicitly in your expression:
[A-Za-z0-9 \-_.äöüß etc]
or use unicode ranges, e.g
[A-Za-z0-9 \-_.\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF]
(see http://www.utf8-chartable.de/ for reference).
Answered By - georg
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.