Page 1 of 1

Help?use Regex that acceps both english and greek characters

Posted: Thu Jul 05, 2012 3:03 am
by Lykos22
Hi I would like some help please if its possible.
I' m having a contact form in which the user submits his name. I use both in my javascript and php validation this regex:

/^[A-Z][A-Za-z.'\- ]+$/

for validatin the name, accepting only characters, whitespaces and - symbol. Although it works fine with english (latin characters), it doesn't work with greek. I want my regex to accept both english and greek characters, so when the user submits his name either in english either in greek it will "pass", if he enters any number or symbol like @,!,* etc (exept whitespaces, ' , -) fails.

Any help would be appreciated.

Re: Help?use Regex that acceps both english and greek charac

Posted: Mon Jul 09, 2012 2:48 pm
by tr0gd0rr
If php is compiled to accept the "u" modifier you can use the Letter property code which is rendered "\p{L}":

Code: Select all

preg_match('/^[\p{L}\.\'\- ]+$/u', $subject);
The "L" property code will accept letters in any language. If you just want only English and Greek letters, you need to find the Unicode range for Greek. Perhaps [a-z\x0370-\x1FFE]? See Wikipedia's info on Unicode ranges for Greek.

Also test it on your server to ensure the "u" modifier is enabled.