0

i have made a function to validate email using pattern. my function is not properly validating it. please help and post ur answers much in detail as possible. Thank you.

function getemail(data){
    var pattern= /^([a-z][a-z0-9\.]+[a-z0-9])@([a-z][a-z0-9\-]+[a-z0-9])\.([a-z]{2,})(\.[a-z]{2,})$/;
    if (data==="") 
        {
            console.log("Email-id cannot be empty!");

        }
    else if(pattern.test(data)===false)
    {
        console.log("Enter a valid emailid");
    }
    else
    {
        var email= "<p>"+data+"</p>";
        return email;
    }
}
Vishnuprasad
  • 113
  • 7

2 Answers2

0

Just try it

var pattern= /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
Jon
  • 87
  • 1
  • 5
0

 function Validation() {
        var regemail = /(.+)@(.+){2,}\.(.+){2,}/;  //Regex Pattern for Email Validation 
        //Email TextBox  Validation
        if (regemail.test($('#<textboxid>').val())) {
             alert('Entered Email id is correct');
        }
        else {
           alert('Please enter valid email Address');
           
        }
     }