PHP.. How to check valid email error?

10 replies
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
#check #email #error #php #valid
  • {{ DiscussionBoard.errors[7750439].message }}
  • Profile picture of the author LordKaT
    Linux Journal has an excellent article on validating that a given e-mail address conforms to the RFC specification, check it out.
    {{ DiscussionBoard.errors[7750523].message }}
  • Profile picture of the author SteveSRS
    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!
    {{ DiscussionBoard.errors[7753058].message }}
  • Profile picture of the author MartinPlatt
    Originally Posted by rrahman View Post

    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...
    Signature

    Martin Platt
    martin-platt.com

    Stuck with earning commissions online? Get this get this uncensored affiliate marketing guide for free (sold as coaching for $4,997)

    {{ DiscussionBoard.errors[7753060].message }}
  • Profile picture of the author dwoods
    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;

    {{ DiscussionBoard.errors[7753624].message }}
  • 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
    Signature
    Outsource to the experts...

    We customize your Blog, eBook, Press Release and Sale Copy content with your message.

    {{ DiscussionBoard.errors[7756651].message }}
  • Profile picture of the author ankur625
    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."; }
    Signature
    {{ DiscussionBoard.errors[7763977].message }}
  • Profile picture of the author Amirol
    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.
    Signature

    Need help with PHP and Laravel?

    {{ DiscussionBoard.errors[7775936].message }}
  • Profile picture of the author sktthemes
    Hello
    Use PHP built in functions

    if(filter_var($mail, FILTER_VALIDATE_EMAIL))
    {
    echo "Mail is valid!";
    }
    {{ DiscussionBoard.errors[8318412].message }}
  • Profile picture of the author otfromtot
    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,
    ); 
    {{ DiscussionBoard.errors[8324471].message }}

Trending Topics