Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP and regexp to accept only Greek characters in form

Tags:

regex

php

I need a regular expression that accepts only Greek chars and spaces for a name field in my form (PHP). I've tried several findings on the net but no luck. Any help will be appreciated.

like image 599
bikey77 Avatar asked Jun 06 '11 16:06

bikey77


2 Answers

Full letters solution, with accented letters:

/^[A-Za-zΑ-Ωα-ωίϊΐόάέύϋΰήώ]+$/
like image 142
leo pal Avatar answered Sep 19 '22 13:09

leo pal


I'm not too current on the Greek alphabet, but if you wanted to do this with the Roman alphabet, you would do this:

/^[a-zA-Z\s]*$/

So to do this with Greek, you replace a and z with the first and last letters of the Greek alphabet. If I remember right, those are α and ω. So the code would be:

/^[α-ωΑ-Ω\s]*$/
like image 20
Justin Morgan Avatar answered Sep 18 '22 13:09

Justin Morgan