Posts Tagged ‘valiating email’

Validating email via regular expression

Tuesday, February 23rd, 2010

You have an online form.

You want to validate every field,  especially email input fields.

You do not want just check if its has a value of not, but also if its in the right format (e.g. email@email.com).

If you answered yes to all of these then the function below if perfect for you.

Check it out…

function validate_email($email){
     if(!eregi("^([[:alnum:]]|_|\.|-)+@([[:alnum:]]|\.|-)+(\.)([a-z]{2,4})$", $email)){
	  return $error=1;
     }
}

Fell free to abuse…