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
https://forums.phpfreaks.com/topic/271680-error-preg_match-bad-words-on-an-email/
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.

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.)

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.