PHP.. How to check valid email error?

by rrahman 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
#programming #check #email #error #php #valid
Avatar of Unregistered
  • Profile picture of the author nathan1
    Signature
    Quality Ties at Affordable Prices
    Men's Tie Deals
    Promo code WARRIOR = 10% off!
    {{ 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

    {{ 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;

    Signature
    Need a way to drive traffic to your new site?
    -- Check out HelpMyHits.com!
    {{ 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."; }
    {{ 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 }}
Avatar of Unregistered

Trending Topics

  • 2 {{ upvoteCount | shortNum }}

    Social Media Marketing Success Factors

    Rajeev Gaur in Social Networks

    Hi all, How can we measure the success rate of social media marketing for a SERP? What factors decide the success? Thanks in advance

  • 3 {{ upvoteCount | shortNum }}

    Generating Leads for Free

    Hello Guys, Whichever Business I have, is it possible for me to generate hundreds of leads per day without spending a single penny? Will you please let me know the ... [read more]

  • 2 {{ upvoteCount | shortNum }}

    1 Dofollow link = how many no follow links?

    avemfly619619 in SEO

    Anyone know about no follow links? Can you suggest me How many no follow should I create in a day? Can you suggest me How many Do follow should I ... [read more]

  • 16 {{ upvoteCount | shortNum }}

    How much should I charge for being a webmaster?

    QMcLau in Internet Marketing

    A family member wants me to make them a website, and for me to act as a webmaster. I'll basically do everything - design, technical stuff, servers and hosting, security, ... [read more]

  • 66 {{ upvoteCount | shortNum }}

    How do I get more clicks or traffic on a particular keyword?

    Nikhil Bansal in SEO

    I have some keywords that have a great ranking on Google, but they don't have clicks and traffic, so I want to know how can I get more traffic and ... [read more]