Jump to content

Username Validation


master82

Recommended Posts

I've been having a few problems with users signing up with usernames that contain special characters, so I have decided to 'tweek' my registration authentication script to disallow special characters.

So how would I go about validating a username input to check that it only contains letters, numbers or a mixture of both?

eg

if($_POST['username'] != [color=navy]+letters and/or numbers+[/color])
{
something
}
else
{
something else
}
Link to comment
https://forums.phpfreaks.com/topic/22108-username-validation/
Share on other sites

Thanks for that - came up with this, but not sure exactly how to put it into the code.

[code]
ereg("^[0-9a-zA-Z]{4,10}$", "$username")
[/code]

Would this work...

[code]
if(ereg("^[0-9a-zA-Z]{4,10}$", "$username"))
{
bla
{
else
{
bla bla
}
[/code]

Also I understand the first part, it is looking for alphnumeric characters, but what is the {4,10} part doing? is this looking at the length? (a simple guess)
Link to comment
https://forums.phpfreaks.com/topic/22108-username-validation/#findComment-98978
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.