Jump to content

Archived

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

master82

Username Validation

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
}

Share this post


Link to post
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)

Share this post


Link to post
Share on other sites
Yes, the {4, 10} is looking at length.  It specifies at least 4 characters, at most 10 characters.

Share this post


Link to post
Share on other sites

×

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.