2
Reply

How to validate an email address in JavaScript

How to validate an email address in JavaScript

    Hi,
    We can validate the email address using regex in JavaScript.

    1. function ValidateEmail(inputText)
    2. {
    3. var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
    4. if(inputText.value.match(mailformat))
    5. {
    6. return true;
    7. }
    8. else
    9. {
    10. return false;
    11. }
    12. }

    Email Validation in JavaScript – Step by Step
    Validating email is a very important point while validating an HTML form. An email is a string or a subset of ASCII characters that are separated into two parts by “@” symbol.

    The first part can consist of the following ASCII Characters:

    Uppercase (A-Z) and lowercase (a-z) letters
    Digits (0-9)
    Characters such as ! # $ % & ‘ * + – / = ? ^ _ ` { | } ~
    Character . ( period, dot or fullstop) but it should not be the first or last character and should not come one after the other