Email Validator

Hi,

Does anyone know of a email address validator plugin for JS or jQuery that I can attach to my form?
APD TorontoAsked:
Who is Participating?
 
Pawan KumarDatabase ExpertCommented:
Please refer old EE question for email validation -

<!DOCTYPE html>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.min.js"></script>

<html lang="en">
<head>
    <title>email validator</title>
<body>
<form>
<input type="text" placeholder="email" name="email" required>
<input type="submit" value="Create Account">
</form>

<script>
var validations ={
    email: [/^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/, 'Please enter a valid email address']
};
$(document).ready(function(){
    // Check all the input fields of type email. This function will handle all the email addresses validations
    $("input[type=text]").change( function(){
        // Set the regular expression to validate the email 
        validation = new RegExp(validations['email'][0]);
        // validate the email value against the regular expression
        if (!validation.test(this.value)){
            // If the validation fails then we show the custom error message
            this.setCustomValidity(validations['email'][1]);
            return false;
        } else {
            // This is really important. If the validation is successful you need to reset the custom error message
            alert("Success ");
            this.setCustomValidity('');
            return true; 
        }
    });
})
</script> 
</body>
</html>

Open in new window



https://www.experts-exchange.com/questions/29012121/email-validation.html#a42067883
0
 
Chris StanyonCommented:
Take a look at the jQuery Validatation plugin:

https://jqueryvalidation.org/email-method/

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Chris Stanyon</title>

        <script src="//ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
        <script src="//cdn.jsdelivr.net/jquery.validation/1.16.0/jquery.validate.min.js"></script>

        <script type="text/javascript">
        $(document).ready(function() {
            $("#myForm").validate({
                rules: {
                    email: {
                        required: true,
                        email: true
                    }
                }
            });
        }); 
        </script>
    </head>

    <body>
        <form method="post" id="myForm">
            <input type="email" name="email">
            <input type="submit" value="Go">
        </form>
    </body>
</html>

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.