PHP Email Validation

Email validation is very important in application development. Here I show you a sample PHP code on how to validate email address.

<?php
function isEmail($email){
	if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){
		return false;
	}else{
		return true;
	}
}

$email = 'test@test';

if(!isEmail($email)){
	echo 'Invalid email address';
}else{
	echo 'Ok';
}

?>

The output is…

function isEmail($email){
if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){
return false;
}else{
return true;
}
}

$email = 'test@test';

if(!isEmail($email)){
echo '

‘;
echo ‘Invalid email address’;
echo ‘

‘;
}else{
echo ‘

‘;
echo ‘Ok’;
echo ‘
‘;
}
?>

As simple as that. Try it by yourself.

PG

Author: insic

Subscribe in my RSS Feed for more updates on Web Design and Development related articles. Follow me on twitter or drop a message to my inbox.

Related Post

Delicious

3 Responses to “PHP Email Validation”

  1. try to visit
    regexlib.com
    for more regex for email.

Leave a Reply