strlen($username);
Username can carry ASCII, Unicode or both.
Example:
Jam123 (ASCII) – 6 characters
ابت (Unicode) – 3 characters but strlen returns 6 bytes as unicode is 2 bytes per char.
Jamت (Unicode and ASCII) – 5 characters (3 ASCII and 2 Unicode even though i have only one unicode character)
Username in all cases shouldn’t go beyond 25 characters and shouldn’t be less than 4 chars.
My main problem is when mixing Unicode and ASCII together, how can i keep track of count so the condition statement can deicde whether username is not over 25 and not less than 4.
if(strlen($username) <= 25 && !(strlen($username) < 4))
3 characters in unicode will be counted as 6 bytes which causes trouble because it allows user to have a username of 3 unicode characters when the characters should be minimum of 4.
Numbers will always be in ASCII
Use
mb_strlen(). It takes care of unicode characters.Example: