Page 1 of 1

Not allowing characters

Posted: Wed Aug 17, 2005 8:20 pm
by s.dot
I don't want my users to sign up with a period in their screenname. I've tried a bunch of stuff to no avail. Someone lend me a pointer?

Posted: Wed Aug 17, 2005 8:25 pm
by feyd
what do you want to perform if these illegal characters are found? A preg_match() or looping over a string of illegal characters doing checks on each could tell you if one was in the string. Alternately, you could just replace them with nothing, for example, using str_replace() or preg_replace()..

Posted: Wed Aug 17, 2005 9:02 pm
by s.dot
I would like to alert the user that it's not allowed. preg_match would require a regex, right?

Posted: Wed Aug 17, 2005 9:14 pm
by feyd
correct.

Code: Select all

if(preg_match('#\.#',$string))
{
  // there's a period
}
else
{
  // there isn't a period
}

Posted: Wed Aug 17, 2005 9:15 pm
by shoebappa
ctype has some pretty cool functions...

http://us2.php.net/manual/en/function.ctype-alnum.php