Posted By

tuffo19 on 10/02/10


Tagged

email php validation


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

bobbym245
tuffo19
batandwacolani


Validate email address


 / Published in: PHP
 

URL: email_validator

Definitivo. Errore bassissimo.

  1. $pattern = "/^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i";
  2.  
  3. if(preg_match($pattern, "mac.doanl[email protected]"))
  4. echo "ok";
  5. else echo "no";

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: erik240 on October 2, 2010

Please don't use this for email validation. It fails for so many valid email addresses. Take, for example, a google address with a tag:

[email protected]

Its a perfect valid email address but the regex fails it. A regex CAN'T properly validate an email according to the RFC, and if you really want to learn how to do it properly, read:

http://www.dominicsayers.com/isemail/

Posted By: erik240 on October 2, 2010

Please don't use this for email validation. It fails for so many valid email addresses. Take, for example, a google address with a tag:

[email protected]

Its a perfect valid email address but the regex fails it. A regex CAN'T properly validate an email according to the RFC, and if you really want to learn how to do it properly, read:

http://www.dominicsayers.com/isemail/

Posted By: tuffo19 on February 22, 2011

maybe you are right, but i need a validator very strict. if it fails for a valid email, the user can always contact me and convince me his email address is valid!

You need to login to post a comment.