Hello Programmers Please help me on creating Javascript program on email validation using loops. Thankyou
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! "); }
^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
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:
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):