Jump to content

[SOLVED] preg_match to block email address(es)


zc1

Recommended Posts

Hi,

 

I have found the below code I change it to *.EXT instead of the ending of the email address for example *.com

 

Now if someone had [email protected] would the below code echo the message or would it let it pass and only block [email protected] ?

 

Also does anyone know if it is case sensitive ?

 

Finally how would I have to to check for .EXT and .EXT1 etc..., would I need to repeat the code or can I have it all within the same code, if so how ?

 

// test block of *.EXT emails

if ( preg_match( "#\.EXT$#", $email ) ) {

echo 'The email address you entered is not allowed.';

exit;

}

 

 

 

Regards,

Garry

hope this helps

 

// test block of *.EXT emails
if ( preg_match( "#(?:\.EXT||\.co\.uk||\.EXT1||\.EXT2)$#i", $email ) ) { //NOTE the i after the # (for case insensitive)
echo 'The email address you entered is not allowed.';
exit;
}

Hi,

 

I had just tested this and I don't think it working right as the message is displaying all the time, even when .ext or .ext1 not in the email address.

 

I have made a test script to test it, see below for code

<?php
$email = '[email protected]';
echo $email;
echo '<br><br>';
// test block or *.EXT and *.EXT1 emails
//if ( preg_match( "#\.EXT$#i", $email ) ) {
if ( preg_match( "#(?:\.EXT||\.EXT1)$#i", $email ) ) { 

echo 'The email address you entered is not allowed.';
exit;
}
?>

 

Any idea why ?

LOL, my bad

 

|| should be |

this should work

 

<?php
$email = '[email protected]';
echo $email;
echo '<br><br>';
// test block or *.EXT and *.EXT1 emails
//if ( preg_match( "#\.EXT$#i", $email ) ) {
if ( preg_match( "#(?:\.EXT|\.EXT1)$#i", $email ) ) { 

echo 'The email address you entered is not allowed.';
exit;
}
?>

 

|| = OR in PHP

|  = OR in RegEx

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.