ereg allow space? Simple for those who understand it

Posted by lexington, 09-21-2008, 10:46 PM
I do not think I will ever fully understand ereg, eregi, or preg match since the tuturials I have read are far too confusing to customize so I can only grab examples off of the net. I created the following validation to prevent users from using anything but numbers and letters in their username: It works, but the problem is if the user adds a space it calls up this error as well. I would like users to have spaces in their username so how can that ereg be modified to work with spaces? Please provide a working example and thanks! Last edited by lexington; 09-21-2008 at 10:49 PM.

Posted by lexington, 09-21-2008, 11:07 PM
Ah nm I figured it out. Surprised how simple it is: Just added a "space" after the 9.

Posted by Tim Greer, 09-21-2008, 11:09 PM
You can (and should) strip off leading and trailing white spaces, and then you can just allow valid "word characters" and a space between, and more word characters, unless you expect there will be more white space. I.e., instead of just JohnSmith and John Smith, you have John Jonas Smith. You can account for that as well. It depends on what you want to do, but regular expressions are pretty easy, actually. Just to allow white space with the existing example, you could use: \s is white space.

Byla tato odpověď nápomocná?

 Tisknout tento článek

Také čtěte

Emails sent with PHP often end up in spam/junk folder

Posted by redtail, 03-07-2010, 07:32 PMMy website on VPS with Hostgator sends out emails to...

I'm looking for a PHP PDF Invoice Maker Script

Posted by Freekers, 03-06-2007, 01:58 PMHello ! I'm looking for a cheap or free PHP PDF Invoice...

disable php functions?

Posted by Calibaba, 09-15-2007, 06:28 PMDoes the below look good for a private server (linux,...

PlanetDomain API - Frustrating - Waiting for almost a decade!

Posted by MrLeN, 09-21-2008, 10:55 AMI have been a PlanetDomain reseller for about 8 years or so...

VB question

Posted by hopesfall, 03-10-2010, 12:42 AMI have a string of asterisks "*****" which are in...