How Do I Make A Username Require _ In A Form

Hello. I have a php, mysql and jquery login and registration sliding system, all works fine but if this requires a new user to use between 4 and 32 characters:

[php]if(preg_match(’/[^a-z0-9-_.]+/i’,$_POST[‘username’]))
{
$err[]=‘Your username contains invalid characters!’;
}[/php]

How do I make it so the use HAS to have a name example of: John_Doe (with the underscore in the middle of the name) both parts of the name having to be 4 or more characters.

I think I’ve fixed the 4 or more character part by changing the above code to 9 or more (John_Test), like this or more.

I will appreciate your help very much, I am making a San Andreas Multiplayer roleplaying community and need the registration system set up correctly.

That’s not going to check the length of the string, all it does is check the characters. to do that, you’d need to use strlen().
[php]if(strlen($_POST[‘username’]) > 4 && strlen($_POST[‘usernae’]) < 32) {
if(!preg_match(’/[^a-z0-9-_.]+/i’,$_POST[‘username’])) {
$err[] = ‘Your username contains invalid characters!’;
}
} else {
$err[] = “Username must be between 4 and 32 characters”;
}[/php]

Please close this post because I have now registered my username and it won’t let me edit it. I have made a new one, I posted the wrong part of my script in this one. Thanks!

Sponsor our Newsletter | Privacy Policy | Terms of Service