Jump to content

[SOLVED] How to exclude a space character from being checked


Brandon Jaeger

Recommended Posts

May I recommend switching from ereg to preg. As for PHP 6+, ereg support will be dropped. You can learn about preg here.

 

As for your regex, you can use \s, but be mindful that this will encompass many forms of spaces (tabs, return carriages, newlines, etc..). So if you want a space explicitly, you can use \x20 (or a literal blank space). Looking at your ereg, here is what I would have done as the equivalent in preg (with the space issue).

 

$match = array();
preg_match('#[^a-z\d\x20]#i', $post_username, $match);

 

I know you'll have some questions about this.. so I'll explain it (but I recommend you have a look at the link above to really familiarize yourself with PCRE).

between the delimiters (# characters), in a character class, match anything that is not a-z or 0-9 (represented as \d - for any digit) or a space. Notice the i after the closing # delimiter? This means case insensitive (so it will in essence match a-z or A-Z). Every match is stored into the array $match.

 

Hope this helps out.

 

Cheers,

 

NRG

 

 

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...

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.