PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
It is currently Sat Mar 23, 2019 10:55 am

All times are UTC - 5 hours

Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Thu Jul 05, 2012 3:03 am 
Forum Newbie

Joined: Thu Jul 05, 2012 2:24 am
Posts: 2
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.

PostPosted: Mon Jul 09, 2012 2:48 pm 
Forum Contributor
User avatar

Joined: Thu May 11, 2006 8:58 pm
Posts: 305
Location: Utah, USA
If php is compiled to accept the "u" modifier you can use the Letter property code which is rendered "\p{L}":
Syntax: [ Download ] [ Hide ]
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.

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours

Who is online

Users browsing this forum: No registered users and 5 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group