Reputation: 199
I have this regular expression ^[A-Za-z]{2,3}[0-9]{3,4}$
with which I validate in an input field so that it has 2 or 3 letters and 3 or 4 numbers
I want to accept only greek characters.
I tried this ^[α-ωΑ-Ω]{2,3}[0-9]{3,4}$
from PHP and regexp to accept only Greek characters in form but with no luck
i also tried ^[\p{Greek}]{2,3}[0-9]{3,4}$
but again no luck
Any suggestions?
VALID STRINGS: ΚΚΞ542 OOP8888 ΠΠ8965 INVALID STRINGS: 555555 K879 ΓΗΥΟ565
Upvotes: 1
Views: 3707
Reputation: 626903
You may match chars with \p{Greek}
and you must use the /u
modifier:
'~^\p{Greek}{2,3}[0-9]{3,4}$~u'
See the regex demo.
Pattern details
^
- start of string\p{Greek}{2,3}
- 2 or 3 Greek chars[0-9]{3,4}
- 3 or 4 ASCII digits$
- end of string.Upvotes: 4