Jump to content

Recommended Posts

When it comes to things like this.. I prefer to use:

 

$email = filter_var(filter_var($_POST['email'], FILTER_SANITIZE_EMAIL), FILTER_VALIDATE_EMAIL);
if($email === true){
   // Since condition is true, do this...
} else {
   // Otherwise it is false, do that...
}

 

The idea is passing your $_POST variable through PHP's built in sanitiser and validation system and assigning it to the variable $email. One issue with building your own custom expressions for such tasks is that if it is built too strict (isn't flexible enough), you may be blocking out certain email adressess..

 

Case in point..suppose the back end of your expression only matches for either '.xx' (which could represent .ca for instance) -or- '.xxx' (to accomodate .com for instance), or .xx.xx (think .co.uk).. well, what happens when someone sends an email with '.asia' ?

 

From what I'm gathering, it is better to be 'loose fisted' as opposed to 'tight fisted'. So these built in functions stays *somewhat* true to email formats, yet is forgiving to some extent (which is recommended for the sake of allowing more emails that would otherwise not make it through).

 

Just a thought.

 

Cheers,

 

NRG

 

EDIT: I am also going to hazzard a guess that this system allows for future domain extended formats that may arise without the need to retool anything.

Link to comment
https://forums.phpfreaks.com/topic/119952-email-regex/#findComment-618079
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.