please help with email validation, preg_match

Discussion in 'PHP' started by nat000, Nov 6, 2009.

  1. #1
    Hi guys

    I need the best available preg_match regular expression to validate email addresses.
    The expressions I've found failed with one of the following emails:


    >
    someemail/r@somedomain.com

    etc.

    Thanks!
     
    nat000, Nov 6, 2009 IP
  2. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #2
    JAY6390, Nov 6, 2009 IP
  3. kbluhm

    kbluhm Peon

    Messages:
    23
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Give filter_var() a shot:
    
    function is_email( $email )
    {
        return FALSE !== filter_var( $email, FILTER_VALIDATE_EMAIL );
    }
    
    PHP:
    Of your three examples, the first two are invalid, but the third is valid, as forward slashes are allowed in the local portion.

    http://en.wikipedia.org/wiki/E-mail_address#RFC_specification
     
    kbluhm, Nov 6, 2009 IP