Regular expression for validating email address

A simple regular expression (regex) for validating email address using PHP which I used mostly on my web apps.
I love being a Web developer and it’s been a lot of fun — this is one of them

<?php
function validateEmail($email) {
	if (ereg("^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@+([_a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]{2,200}\.[a-zA-Z]{2,6}$", $email)) {
		return true;
	} else {
		return false;
	}
}
?>

Usage:

<?php
if (validateEmail($email)) {
	// Email address is valid, do your process here...
} else {
	// Email address is not valid, do your process here...
}
?>
Tagged with 
About sepedatua
I am nothing special, of this I am sure. I am a common man with common thoughts and I’ve led a common life. There are no monuments dedicated to me and my name will soon be forgotten, but I’ve loved another with all my heart and soul, and to me, this has always been enough.

Leave a Reply