Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Amend Regular Expression to allow German umlauts, French accents and other valid European letters

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äöüÄÖÜ \-_.]*$/"

like image 962
Mike Sav Avatar asked Sep 25 '13 09:09

Mike Sav


People also ask

What German letters have Umlauts?

The Umlaut is the pair of dots placed over certain vowels; in standard German and its dialects, these vowels are ä, ö, ü.

How do I verify a first name and last name?

Using JavaScript, the full name validation can be easily implemented in the form to check whether the user provides their first name and last name properly. The REGEX (Regular Expression) is the easiest way to validate the Full Name (first name + last name) format in JavaScript.

How do you write names in regex?

String regularExpression= "^[A-Za-z][A-Za-z0-9_]{7,29}$"; A valid username should start with an alphabet so, [A-Za-z]. All other characters can be alphabets, numbers or an underscore so, [A-Za-z0-9_]. Since length constraint was given as 8-30 and we had already fixed the first character, so we give {7,29}.


2 Answers

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).

like image 152
georg Avatar answered Sep 19 '22 15:09

georg


[a-zA-Z\x7f-\xff] contains a lot of special characters such as ä ö ü é ß î...

like image 21
Tobias Mühl Avatar answered Sep 18 '22 15:09

Tobias Mühl