Validate Email using Regular Expression in JavaScript

Source code :

var exp="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$";
var mail ="";
var patt = new RegExp(exp);
if (patt.test(mail)){
    alert("valid email");
    alert("invalid email");

Output :

Valid email

Algorithm :

  1. Initialize the variable for this regular expression [a-z0-9._%+-]+@[a-z0-9.-]+.[a-z]{2,3}$
  2. Enter the test email for validation
  3. Initialize another variable for checking the RegExp(exp)
  4. Check the RegExp(exp) with test email
  5. Finally print the result

Output :


Comments :