Jump to content

[SOLVED] preg_match to block email address(es)


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 abc.EXT@my-domain.co.uk would the below code echo the message or would it let it pass and only block abc@my-domain.ext ?

 

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 = 'xyz@mydomain.com';
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 = 'xyz@mydomain.com';
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

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.