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…

Invalid email address

As simple as that. Try it by yourself.

PG

Author: admin

Related Post

Delicious