Jump to content

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


Brandon Jaeger
 Share

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

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • 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.