PHP and regexp to accept only Greek characters in form
The other answers here didn't work for me. Greek Unicode characters are included in the following two blocks
- Greek and Coptic U+0370 to U+03FF (normal Greek letters)
- Greek Extended U+1F00 to U+1FFF (Greek letters with diacritics)
The following regex matches whole Greek words:
[\u0370-\u03ff\u1f00-\u1fff]+
I will let the reader translate that to whichever programming language format they may be using.
See also
- Unicode charts
To elaborate on leo pal's answer, an even more complete regex, which would accept even capital accented Greek characters, would be the following:
/^[α-ωΑ-ΩίϊΐόάέύϋΰήώΊΪΌΆΈΎΫΉΏ\s]+$/
With this, you get:
α-ω
- lowercase lettersΑ-Ω
- uppercase lettersίϊΐόάέύϋΰήώ
- lowercase letters with all (modern) diacriticsΊΪΌΆΈΎΫΉΏ
- uppercase letters with all (modern) diacritics\s
- any whitespace character
Note: The above does not take into account ancient Greek diacritics (ᾶ, ἀ, etc.).
Full letters solution, with accented letters:
/^[A-Za-zΑ-Ωα-ωίϊΐόάέύϋΰήώ]+$/
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]*$/