开发者

Function to prevent special characters in nickname

开发者 https://www.devze.com 2022-12-21 23:44 出处:网络
开发者_开发知识库I\'ve a website where users can register.I would like to prevent all special characters, accents, etc inthe nickname (used to login).

开发者_开发知识库I've a website where users can register. I would like to prevent all special characters, accents, etc in the nickname (used to login).

I use PHP. How can I do that ?

Edit: Another question, can you give me a regular expression (in PHP) who allow ONLY the 26 letters : abcdefghijklmnopqrstuvwxyz and no more ?

Thanks


$username = preg_replace('/[^a-z]/i', '', $username);

If you really just mean lowercase a-z, remove the i flag.

In response to comment, the regexp becomes [^a-z0-9]


You could use PHP's normalizer functions for that.

0

精彩评论

暂无评论...
验证码 换一张
取 消