Regex help - How do I only allow these characters: _, ,a-zA-z0-9
I tried using this code, but it didn't work. 🙁
if (!empty($user) && !eregi("[ _a-zA-Z0-9]", $user)) echo "Bad Username.<br />";
Thank you
Ron
// negate the character class with "^" to look for invalid characters: if(!empty($user) && preg_match('/[^\w ]/', $user)) { echo "Bad Username.<br />\n"; }
(In preg*() regexes, \w == [a-zA-Z0-9])
Thank you NogDog, that helped a lot! 🙂
Ofc, you can mark this thread RESOLVED. 🙂
RonB, looks like you were trying to allow the space character to be a legal character in your original post? That opens all kinds of bad doors IMHA. \w doesn't include the space character.