Email Validation

Discussion in 'PHP' started by kirpat10, May 4, 2009.

  1. #1
    Hello Programmers
    Please help me on creating Javascript program on email validation using loops.

    Thankyou
     
    kirpat10, May 4, 2009 IP
  2. wmtips

    wmtips Well-Known Member

    Messages:
    601
    Likes Received:
    70
    Best Answers:
    1
    Trophy Points:
    150
  3. SHOwnsYou

    SHOwnsYou Peon

    Messages:
    209
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    you could also just use this:

    $email = mysql_real_escape_string($_POST['email'])
    if(!$email == "" && (!strstr($email,"@") || !strstr($email,".")))
    {
    echo '<h1>Invalid email address!</h1>';
    die ("Go back! ");
    }
     
    SHOwnsYou, May 4, 2009 IP
  4. sorostitute

    sorostitute Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    ^you could do that, but it'd be a pretty lazy validation. I think regular expressions is the way to go:
    http://www.regular-expressions.info/javascriptexample.html
     
    sorostitute, May 4, 2009 IP
  5. JDevereux

    JDevereux Peon

    Messages:
    50
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    This is the email validation function wordpress uses for comments:

    /**
     * Checks to see if the text is a valid email address.
     *
     * @since 0.71
     *
     * @param string $user_email The email address to be checked.
     * @return bool Returns true if valid, otherwise false.
     */
    function is_email($user_email) {
    	$chars = "/^([a-z0-9+_]|\\-|\\.)+@(([a-z0-9_]|\\-)+\\.)+[a-z]{2,6}\$/i";
    	if (strpos($user_email, '@') !== false && strpos($user_email, '.') !== false) {
    		if (preg_match($chars, $user_email)) {
    			return true;
    		} else {
    			return false;
    		}
    	} else {
    		return false;
    	}
    }
    PHP:
     
    JDevereux, May 4, 2009 IP
  6. darkmessiah

    darkmessiah Peon

    Messages:
    500
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #6
    here's another

    
    	function valid_email($email){
    		return ((preg_match("/[a-zA-Z0-9]+([._][a-zA-Z0-9]+)*@[^ ]+\.[a-zA-Z0-9]/", preg_quote($email))) ? true : false);
    	}
    
    Code (markup):
     
    darkmessiah, May 5, 2009 IP
  7. stevejeff

    stevejeff Peon

    Messages:
    187
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7
    You can try this code:
     
    stevejeff, May 5, 2009 IP