PHP.. How to check valid email error? Hi, I can check field, number of character error. But I don't know how to check valid email error or website error.. I mean if user submit invalid email address or website like without "@" and ".com .net" then script will not run further... How do I create this script? Please help thanks |
Re: PHP.. How to check valid email error? |
Re: PHP.. How to check valid email error? Linux Journal has an excellent article on validating that a given e-mail address conforms to the RFC specification, check it out. |
Re: PHP.. How to check valid email error? Hi, That is a lot of coding in the article above for something that can be done way easier: PHP: Validation - Manual For php questions like this always do a search on php.net almost always helps! |
Re: PHP.. How to check valid email error? Quote:
|
Re: PHP.. How to check valid email error? I've used many regex's over the years -- some strict some not; but my current method for validating email with PHP is using the PHP's pre-baked filter_var() PHP Code: |
Re: PHP.. How to check valid email error? rrahman You could use this, //email validations if(!$this->validate_email($_POST['email'])) { $this->add_error("Please provide a valid email address"); $ret = false; } With this function function validate_email($email) { return eregi("^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$", $email); } Hope that helps, Shawn |
Re: PHP.. How to check valid email error? use this, if(!empty($_POST['email'])) { if(!preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $_POST['email'])){ $errors = "Please enter a valid email address."; } else { $email = mysql_real_escape_string(trim($_POST['email'])); } } else { $errors[] = "You forgot to enter email address."; } |
Re: PHP.. How to check valid email error? Hi, First make sure your input type is email. <input type="email" size="30" value="" /> Then for 2nd layer validation, just use the code provided by dwoods. |
Re: PHP.. How to check valid email error? Hello Use PHP built in functions if(filter_var($mail, FILTER_VALIDATE_EMAIL)) { echo "Mail is valid!"; } |
Re: PHP.. How to check valid email error? I use this in my script PHP Code: |
All times are GMT -6. The time now is 04:23 PM. |