Clive Walkden

PHP, MySQL, HTML5, CSS3, jQuery code and ideas.

PHP Posts

PHP Email Address Validation Function

PHP Email Address Validation Function

in PHP
with 0 Comments

If you want to make sure that an email passed in a form or url variable is actually what you expect it to be then this function can help.

function is_email($email) {
    	return preg_match('/^[a-z0-9!#$%&\'*+\/=?^`{}|~_-]+[.a-z0-9!#$%&\'*+\/=?^`{}|~_-]*@[a-z0-9]+[._a-z0-9-]*\.[a-z0-9]+$/ui', $email);

It simply returns true if the supplied is an email address and nothing (false) if the data passed into it isn't one.

comments powered by Disqus