Last Good Quote: Son's are the seasoning on our lives. - Someone on Facebook

Monday, July 16

PHP Code: Validate Email Address String

A bit of code that will use reqular expressions to
validate an email address.

URL: http://snippets.dzone.com/posts/show/4022

<?

function validate_email($email){

$exp = "^[a-z\'0-9]+([._-][a-z\'0-9]+)*@([a-z0-9]+([._-][a-z0-9]+))+$";

if(eregi($exp,$email)){
if(checkdnsrr(array_pop(explode("@",$email)),"MX")){
print("$email is ok.
");
}else{
print("$email is ok. But domain is not.
");
}
}else{
print("$email is not ok.
");
}
}

validate_email("shantanu.ok");
validate_email("shantanu.ok@gmail.com");
validate_email("shantanu.ok@fsjaldkfjlsfjsljflsfjsldk.com");

?>

2 comments:

ROSE said...

function validate_email($email){

$exp = "^[a-z\'0-9]+([._-][a-z\'0-9]+)*@([a-z0-9]+([._-][a-z0-9]+))+$";

if(eregi($exp,$email))
{
if(checkdnsrr(array_pop(explode("@",$email)),"MX"))
{
print("$email is ok.");
}
else
{
print("$email is ok. But domain is not.");
}
}
else
{
print("$email is not ok.");
}
}

validate_email("shantanu.ok");
validate_email("shantanu.ok@gmail.com");
validate_email("shantanu.ok@fsjaldkfjlsfjsljflsfjsldk.com");



I am used this codes. But I got a fatal error. Why this happen?
My error is:
Fatal error: Call to undefined function checkdnsrr()

Plz give me the answer

ROSE said...

can you give me the explain below coding.
Why using validate_email?

validate_email("shantanu.ok");
validate_email("shantanu.ok@gmail.com");
validate_email("shantanu.ok@fsjaldkfjlsfjsljflsfjsldk.com");

Post a Comment

Followers