Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Very liberal PHP is valid email check.
function isValidEmailAddress($email) {
return (
(preg_match('/^[^\r\n\t]+@[^\r\n\t ]+\.(?i)[a-z]{2,10}$/',$email)) &&
(count($partList = explode('@',$email)) == 2) &&
// valid
// invalid
isValidEmailAddress("my.n\t\r\name@some\"); // \r\n\t characters bad
isValidEmailAddress(""); // spaces in domain component
isValidEmailAddress(""); // multiple "@" characters
isValidEmailAddress(""); // longer than 10 characters TLD
isValidEmailAddress(""); // double (or more) sequential dots

This comment has been minimized.

Copy link

Xeoncross commented Apr 17, 2014

What about control characters or whitespace? Look at the PHP unicode regex rules on


This comment has been minimized.

Copy link
Owner Author

magnetikonline commented Apr 17, 2014

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
You can’t perform that action at this time.