PDA

View Full Version : validating username


xXLeighXx2008
08-20-2008, 12:44 AM
We are creating our own page that is NOT vb powered and we are linking it to a mysql database OUTSIDE vb.

We want to validate our registration page so it does not allow usernames with special characters.. Remember, this is NOT vb powered and will not create the user in vb.

We have been recommended to use the eregi() function but we can't find any tutorials on how to acheive this.

This is simply for a custom php file

Can anyone help?

MoT3rror
08-20-2008, 12:53 AM
if(preg_match('^((?!&#\d+;)[\x20-\x7E])+$', $username'))
{
//username is ASCII characters from 32-127
}
else
{
//username is not valided
}

You can find more patterns here (http://us3.php.net/manual/en/function.preg-match.php).

xXLeighXx2008
08-20-2008, 01:05 AM
We are using the following code and its not working for us.



$username = $_POST['username'];
if(!preg_match('^((?!&#\d+;) [\x20-\x7E])+$', $username)) {
echo ('That is not a valid username.');
}
else {
die();
}

MoT3rror
08-20-2008, 02:11 AM
Is there any error or what is happening?

Opserty
08-20-2008, 08:03 AM
I see a " " (space) before the opening bracket ([) in the regex (in your code), that wasn't in the code given in post #2.

xXLeighXx2008
08-20-2008, 10:57 AM
That was my fault when I copied it over, as it was pasted over MSN messenger and it generated a emoticon.

That wasn't what was pasted into the php file.