#65 is_valid_email modification

open
nobody
None
5
2006-04-14
2006-04-14
Joe Stewart
No

From MikeG and SteveM at Openconcept -

/*
validate email address:
- local part: <=64 characters: letters,numbers,-_+
(note: this is more restrictive than RFC2822,
and may reject
uncommon but valid addresses)
- domain part: LDH format, with 2-4 character TLD,
must pass DNS
lookup
(this, too is slightly restrictive, but LDH is
the defacto
standard, and .museum TLDs are
rare)
** remove second, 'A' lookup to require valid
MX record
*/

function is_valid_email($address) {
$pattern =
'/^([_a-zA-Z0-9-+]+)(\.[_a-zA-Z0-9-+]+)*@(([a-zA-
Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])+)(\.
([a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])+)*(\.[a-zA-Z]{2,4})$/';
if ( preg_match($pattern, $textIn) ) {
list($username,$domain) = split('@', $textIn);
if( ( checkdnsrr($domain . '.','MX') ||
checkdnsrr($domain .
'.','A') ) && strlen($username)
<= 64 ) { return true; }
else { return false; }
}
else { return false; }
}

Discussion