Jump to content


Photo

Username Validation


  • Please log in to reply
3 replies to this topic

#1 master82

master82
  • Members
  • PipPipPip
  • Advanced Member
  • 182 posts

Posted 26 September 2006 - 02:33 PM

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'] != +letters and/or numbers+)
{
something
}
else
{
something else
}

#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 26 September 2006 - 02:35 PM

You should look into Regular Expressions.

Orio.
Think you're smarty?

(Gone until 20 to November)

#3 master82

master82
  • Members
  • PipPipPip
  • Advanced Member
  • 182 posts

Posted 26 September 2006 - 02:57 PM

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

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

Would this work...

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

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)

#4 KevinM1

KevinM1
  • Moderators
  • Snarkimus Prime
  • 5,248 posts

Posted 26 September 2006 - 03:05 PM

Yes, the {4, 10} is looking at length.  It specifies at least 4 characters, at most 10 characters.
Using 'global' is a sign of doing it wrong




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users