Checking a Username for valid characters
Posted: Wed Nov 30, 2005 12:01 am
Hi All,
Trying to figure out something that I have no real knowledge of... preg_match. I search around the boards here and other PHP programming sites and put together the closest thing I could find that suits my needs. BUT... it doesn't work right.
Basically, the username passed to the function should only contain A-Z, a-z, 0-9, the underscore "_" character and no spaces. Anything else should return false.
Am I missing something here or did I format it incorrectly? As I mentioned, preg_matches and ereg calls are new to me.
Thanks in advance,
Best,
Cent
Trying to figure out something that I have no real knowledge of... preg_match. I search around the boards here and other PHP programming sites and put together the closest thing I could find that suits my needs. BUT... it doesn't work right.
Basically, the username passed to the function should only contain A-Z, a-z, 0-9, the underscore "_" character and no spaces. Anything else should return false.
Code: Select all
function checkUsername($uname)
{
return preg_match("/[A-z]+[0-9]+[_]/",$uname);
}Am I missing something here or did I format it incorrectly? As I mentioned, preg_matches and ereg calls are new to me.
Thanks in advance,
Best,
Cent