Using Arabic characters with ctype_alnum

后端 未结 2 1730
一向
一向 2021-01-22 01:20

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,

2条回答
  •  时光取名叫无心
    2021-01-22 01:34

    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.

提交回复
热议问题