Reputation: 7992
I wanted a regular expression that would match Arabic OR English Names that would allow only characters(alphabets) and spaces, I found a JavaScript RegEx that does the job
var regex = /^(?:[a-zA-Z\s\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDCF\uFDF0-\uFDFF\uFE70-\uFEFF]|(?:\uD802[\uDE60-\uDE9F]|\uD83B[\uDE00-\uDEFF])){0,30}$/;
I converted it to PCRE compliant as
/^(?:[a-zA-Z\s\x{600}-\x{6FF}\x{750}-\x{77F}\x{8A0}-\x{8FF}\x{FB50}-\x{FDCF}\x{FDF0}-\x{FDFF}\x{FE70}-\x{FEFF}]|(?:\x{D802}[\x{DE60}-\x{DE9F}]|\x{D83B}[\x{DE00}-\x{DEFF}])){0,70}$/u
however when I try
var_dump(preg_match('/^(?:[a-zA-Z\s\x{0600}-\x{06FF}\x{0750}-\x{077F}\x{08A0}-\x{08FF}\x{FB50}-\x{FDCF}\x{FDF0}-\x{FDFF}\x{FE70}-\x{FEFF}]|(?:\x{D802}[\x{DE60}-\x{DE9F}]|\x{D83B}[\x{DE00}-\x{DEFF}])){0,70}$/u', 'Foo Bar'));
OR
var_dump(preg_match('/^(?:[a-zA-Z\s\x{600}-\x{6FF}\x{750}-\x{77F}\x{8A0}-\x{8FF}\x{FB50}-\x{FDCF}\x{FDF0}-\x{FDFF}\x{FE70}-\x{FEFF}]|(?:\x{D802}[\x{DE60}-\x{DE9F}]|\x{D83B}[\x{DE00}-\x{DEFF}])){0,70}$/u', 'Foo Bar'));
it returns
PHP Warning: preg_match(): Compilation failed: disallowed Unicode code point (>= 0xd800 && <= 0xdfff) at offset 127 in php shell code on line 1 bool(false)
Please help to resolve this warning!
Any help appreciated! Thank You!
Upvotes: 1
Views: 2744
Reputation: 48761
If by letters you mean language main 28 characters you don't even have to construct a code-point based character class (you can build it by typing letters manually!).
But if you mean Arabic
(0600
–06FF
, 255 characters) then again that long character class doesn't provide what you desire.
Anyhow you can go with this:
/^(?!.*\d)[a-z\p{Arabic}\s]+$/iu
Note: you may want to check for different blocks in Arabic script here.
Upvotes: 2