Function validateEmail ($ email) { $ IsValid = true; $ AtIndex = strrpos ($ email ,"@"); If (is_bool ($ atIndex )&&! $ AtIndex) { $ IsValid = false; } Else { $ Domain = substr ($ email, $ atIndex + 1 ); $ Local = substr ($ email, 0, $ atIndex ); $ LocalLen = strlen ($ local ); $ DomainLen = strlen ($ domain ); If ($ localLen <1 | $ localLen> 64) { // Local part length exceeded $ IsValid = false; } Else if ($ domainLen <1 | $ domainLen> 255) { // Domain part length exceeded $ IsValid = false; } Else if ($ local [0] = '.' | $ local [$ localLen-1] = '.') { // Local part starts or ends '.' $ IsValid = false; } Else if (preg_match ('/\. \./', $ local )) { // Local part has two consecutive dots $ IsValid = false; } Else if (! Preg_match ('/^ [A-Za-z0-9 \-\.] + $/', $ domain )) { // Character not valid in domain part $ IsValid = false; } Else if (preg_match ('/\. \./', $ domain )) { // Domain part has two consecutive dots $ IsValid = false; } Else if (! Preg_match ('/^ (\\\\. | [A-Za-z0-9! # % & '_ =\\/ $ \' * +? ^ {} | ~. -]) + $/', Str_replace ("\\\\", "", $ local ))) { // Character not valid in local part unless // Local part is quoted If (! Preg_match ('/^ "(\\\\" | [^ "]) +" $/', str_replace ("\\\\","", $ local ))) { $ IsValid = false; } } If ($ isValid &&! (Checkdnsrr ($ domain, "MX") | checkdnsrr ($ domain, ""))) { // Domain not found in DNS $ IsValid = false; } } Return $ isValid; } ?> |