Sunday, March 23, 2014

PHP Code To Validate Email Address and Domain


This function can Validate Email Address and Domain. Here the Code:
$email = "test test@yahoo.com"; // Invalid Formating
//$email = "testtest@yahoo.comx"; // Invalid Domain
//$email = "testtest@yahoo.com"; // Valid Email

// validate address formating
if (filter_var($email, FILTER_VALIDATE_EMAIL) != FALSE) {
    echo "Valid email address formatting!\n";
}else{
    echo "Invalid formatting\n";
}

// validate domain of email
$domain = substr($email, strpos($email, '@') + 1);
if  (checkdnsrr($domain) !== FALSE) {
    echo "Domain is valid!\n";
}else{
    echo "Domain is not valid!\n";
}
Good Luck !!!

0 comments:

Post a Comment