I need to allow Arabic usernames on my website which is already using ctype_alnum
to validate the username
field. When I try to use Arabic usernames, the validation error message is returned. ctype_alnum
does not recognize arabic characters as letters and numbers. How can i work around this ?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
ctype_alnum only recognizes 0-9A-Za-z.
You can either use regular expressions (as crothhass posted while I was writing this), or you can attempt to convert Arabic into Latin alphabet, check this with ctype_alnum, then convert it back again.
But what I actually recommend is to look at the problem from the other direction, and just check for characters that you DON'T want. This is probably spaces and some punctuation, since you are likely using UTF-8 anyway and can accept anything else.
You can find all Arabic Characters by using this Regex:
If the matched length equals the username length it is an arabic username.