By 18/02/2014 8 Comments

How To Validate Email using Javascript

What is an Email Validation?

  • An Email validation lets the user to enter a valid or correct email address in the website
  • The validation rule checks the email format
  • Using Javascript function, an email can be easily validated, described as following
  • An Email validation in Javascript is called client side validation

In this article, we discuss about email validation using javascript means client side email validation with help regular expression.

Javascript Code Snippet

    <script type="text/javascript">

        function ValidateEmail(email) { // function which perform email validation task pass 1 parameter email

            var reg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; // a regular expression which checks email is valid or not

            if (reg.test(email)) { // regular expression calls test function if success return true otherwise false

                return true;

            } else {

                return false;

            }

        }

    </script>

HTML Code Snippet

<form>

        <input type="text" id="email" /> <!--create a text field input with an id email--->

        <button onclick="alert(ValidateEmail(document.getElementById('email').value));">Validate</button> <!--create a button and it calls javascript ValidateEmail function pass given email to that function as an argument--->

 </form>






Posted in: HTML, JavaScript

Leave your valuable Comment

Have a natural attraction for women cosmetics and replica watches uk clothes, no
more than two for men the most attractive one, is to make their own driving experience, happy and can serve as the facade of the car, another is to highlight the taste edify sentiment rolex replica watch. The replica rolex is undoubtedly the most fashionable accessories, wear a suit to attend the activities, but also get a decent match on the replica watches .