PHP: Register> USERNAME with only Greek characters and only one space

I would like my user to be able to write Greek characters with only one space between their first and last name. How do I change this PHP code for this?

!preg_match("/^[A-Za-z0-9_!@$]{1,50}$/", $newusername)

      

+3


source to share


1 answer


You want to use a modifier/u

so that the Unicode expression is known, and I prefer to use hex codes when specifying this kind of thing - it's hard to tell alpha (A) from ay (A).

According to Wikipedia , the "Greek and Coptic" Unicode block uses codes from 0x370 to 0x3ff:



function checkGreek($newusername) {
    if (preg_match("/^[\x{370}-\x{3FF} ]{1,50}$/u", $newusername)) {
        echo "It Greek to me";
    } else {
        echo "Non-Greek in there";
    }
}
checkGreek("ΑΒ ΓΔ");
checkGreek("ΑΒ ΓΔ 123");
checkGreek("AB CD");

      

+1


source







All Articles