Not allowing characters

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Not allowing characters

Post 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?
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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()..
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

I would like to alert the user that it's not allowed. preg_match would require a regex, right?
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

correct.

Code: Select all

if(preg_match('#\.#',$string))
{
  // there's a period
}
else
{
  // there isn't a period
}
User avatar
shoebappa
Forum Contributor
Posts: 158
Joined: Mon Jul 11, 2005 9:14 pm
Location: Norfolk, VA

Post by shoebappa »

ctype has some pretty cool functions...

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