Warrior Forum - The #1 Digital Marketing Forum & Marketplace

Warrior Forum - The #1 Digital Marketing Forum & Marketplace (https://www.warriorforum.com/)
-   Programming (https://www.warriorforum.com/programming/)
-   -   PHP.. How to check valid email error? (https://www.warriorforum.com/programming/755028-php-how-check-valid-email-error.html)

rrahman 17th February 2013 10:28 AM

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

nathan1 17th February 2013 10:32 AM

Re: PHP.. How to check valid email error?
 
best validator

LordKaT 17th February 2013 11:02 AM

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.

SteveSRS 18th February 2013 02:42 AM

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!

MartinPlatt 18th February 2013 02:43 AM

Re: PHP.. How to check valid email error?
 
Quote:

Originally Posted by rrahman (Post 7750433)
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

You should be able to check it using a regular expression. Should be plenty of examples on Google...

dwoods 18th February 2013 07:20 AM

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:

//best way is with php5 filters: 
if(!filter_var(, FILTER_VALIDATE_EMAIL)){
    return 
false;



TheContentAuthority 18th February 2013 08:25 PM

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

ankur625 20th February 2013 12:12 PM

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."; }

Amirol 23rd February 2013 12:34 AM

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.

sktthemes 24th July 2013 07:28 AM

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!";
}

otfromtot 25th July 2013 02:26 PM

Re: PHP.. How to check valid email error?
 
I use this in my script
PHP Code:

 = array(
    
'first_name' => array(
        
'filter' => FILTER_VALIDATE_REGEXP,
        
'options' => array('regexp' => '/^[a-z- ]{3,20}$/i'),
    ),
    
'last_name' => array(
        
'filter' => FILTER_VALIDATE_REGEXP,
        
'options' => array('regexp' => '/^[a-z- ]{3,20}$/i'),
    ),
    
'phone' => array(
        
'filter' => FILTER_VALIDATE_REGEXP,
        
'options' => array('regexp' => '/^[0-9-]{7,20}$/i'),
    ),
    
'email' => FILTER_VALIDATE_EMAIL,
); 



All times are GMT -6. The time now is 04:23 PM.