validating username
| From: | Sudhakar | Date: | Mon, 26 May 2008 07:37:59 +0000 |
| Subject: | validating username | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-274688@lists.php.net to get a copy of this message | ||
i have used the following code to validate the username it is working fine
=============================================
if( $username == "" || !preg_match("/^[a-z0-9]+(?:_[a-z0-9]+)?$/i",
$username) )
{
$error.="User name cannot be blank or has special characters";
}
=============================================
it does not accept UNDERSCORE at the beginning or end however while i was
testing with different special characters except for # the validation works
fine for all other special characters.
for example if i enter the user name as = abc#123 in this case # sign and
what comes after # sign is being ignored. so in this case the username is
being read as abc ONLY and not abc#123
this is very strange, how can i still validate # sign and tell the user that
# sign is not a valid username like i have been doing with any other special
characters like = !@$...........
please advice.
thanks.