I have a simple regular expression to check a username:
preg_match(\'/(*UTF8)^[[:alnum:]]([[:alnum:]]|[ _.-])+$/i\', $username);
In local t
it seems it is an old post but as it is always a subject of interest I will post what I discovered here. It is a small difference but makes code more simple. The thing is that curly brackets are optional.
The above code of Gumbo and Scott can be written more simple like this if someone wants to allow only letters (Unicode & non-Unicode) and blank spaces:
preg_match("/^\pL[\pL ]+$/u",$string)
I also noticed that preg_match accepts even more simple code as the following :
preg_match("/^[\pL ]+$/u",$string)