Jump to content

Error: Preg_Match Bad Words On An Email


GD77

Recommended Posts

Hello,

I m using the following to check on bad words upon an email validation:

 

$badWords=array('...','...');

$words = array_map('preg_quote', $badWords);
$words1 = implode('|', $words);

if(!preg_match('/^[a-z0-9_\-\.]+@(?:[a-z0-9_\-]+\.)+(?:'.$Ext.')+$/', $user_email) || preg_match('/\b'.$words1.'\b/i', $user_email){}


 

The email in question: ericbass213...why is it considering it as badword since it snot listed in the badwords array and yes when I ve disabled the badword validation the email workd fine.

 

Thank

Link to comment
Share on other sites

To give you a small example of what Jessica refers to:

php > $string = "This is clopenasticly wrong, for all testers and unclosed doors";
php > $RegExp = "/\\btest|open|closed\\b/";
php > var_dump (preg_match_all ($RegExp, $string, $matches));
int(3)
php > var_dump ($matches);
array(1) {
 [0]=>
 array(3) {
   [0]=>
   string(4) "open"
   [1]=>
   string(4) "test"
   [2]=>
   string(6) "closed"
 }
}

In other words, \b and | doesn't work quite the way you think. You'll need a non-capturing sub group in there too.

Link to comment
Share on other sites

You're welcome, and yeah: Generally you don't want to filter "bad" words from an e-mail address. It's extremely annoying when I can't sign up for a site, because they've deemed part of my last name a "bad word". :hammer_time:

(For those not in the know: "Fag" in Norwegian means subject/area of study/work.)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

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