Last active
August 29, 2015 13:59
-
-
Save magnetikonline/10965895 to your computer and use it in GitHub Desktop.
Very liberal PHP is valid email check.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function isValidEmailAddress($email) { | |
return ( | |
(preg_match('/^[^\r\n\t]+@[^\r\n\t ]+\.(?i)[a-z]{2,10}$/',$email)) && | |
(count($partList = explode('@',$email)) == 2) && | |
(!preg_match('/\.{2}/',$partList[1])) | |
); | |
} | |
// valid | |
isValidEmailAddress("my.name@somedomain.com"); | |
// invalid | |
isValidEmailAddress("my.n\t\r\name@some\rdomain.com"); // \r\n\t characters bad | |
isValidEmailAddress("my.name@some domain.com"); // spaces in domain component | |
isValidEmailAddress("my.name@som@edomain.com"); // multiple "@" characters | |
isValidEmailAddress("my.name@som@edomain.longtld12334"); // longer than 10 characters TLD | |
isValidEmailAddress("my.name@some..domain.com"); // double (or more) sequential dots |
Whitespace in the domain portion, good point - but it IS valid in the name@ part if the name is quoted.
Trying not to be too intense here with the checking :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What about control characters or whitespace? Look at the PHP unicode regex rules on php.net