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 :thumbup:

<?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...
}
?>

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.

If you enjoyed this post, make sure you subscribe to our RSS Feed! Or if you prefer, you can Follow us on Twitter instead.