How to match non-ASCII (German, Spanish, etc.) letters in regular expression?

I was unable to find or create a regular expression that matches only letters, spaces, accented letters, and Spanish and German letters.

I am using this now:

var reg = new RegExp("^[a-z _]*$");

I tried:

^[:alpha: _]*$   
^[a-zA-Z0-9äöüÄÖÜ]*$  
^[-\p{L}]*$   

Any idea? Or is the regex supported by javascript engines limited?

+3
source share
2 answers

From the second to the last case, it looks like it should work, but the "and" _ are missing:

/^[a-zA-Z0-9äöüÄÖÜ]*$/.test("aäöüÄÖÜz") => true in FF 3.6 and IE8

/^[a-zA-Z0-9äöüÄÖÜ]*$/.test("é") => false in FF 3.6 and IE8

I cannot find other constructs in the ECMAScript specification .

Happy coding.

, "unicode" (, UTF-8). , escape- \uXXXX ( / ).

+3

, , , , :

^[a-zA-Z\-ÀàÂâÆæÇçÈèÉéÊêËëÎîÏïÔôŒœÙùÛûÜü]*$

, "Rölf-Dieter", . , !

+1

All Articles