So I am designing a registration page and checking the username is alphanumeric.
else if(!eregi("^([0-9a-z])+$", $subuser)){
$form->setError($field, "* Username not alphanumeric");
I use that to do so. Is there any way I can get that to include underscores (_), dash (-), and spaces?
Thanks
You can use:
You just need to add an
underscore(_), ahyphen (-)and aspace( )to the char class. Of the three only hyphen has special meaning in the char class but only if its surrounded on both sides by char. So to avoid this you can include it at the beginning or at the end. You can also include it in the middle and escape it.So the following are also valid: