1
var emailRegex =/^(?("")(""[^""]+?""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)
(?<=[0-9a-z])@))(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-\w]*[0-9a-z]*\.)+[a-z0-9]{2,24}))$/ 

above pattern for email validations giving Error:

")" is not valid at the start of a code block. 
 Only identifiers, keywords, comments, "(" and "{" are valid.   
Jigar Pandya
  • 6,004
  • 2
  • 27
  • 45

2 Answers2

0

Using regular expressions is probably the best way.

function validate(email) { 
var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;  
if (emailPattern.test(email.value) == false) 
    {
        alert('Invalid Email Address');
        return false;
    }

    return true;
}

This should be validated on the server side as well.

Ajay
  • 6,418
  • 18
  • 79
  • 130
0

try this pattern

 var pattern = /^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$/;

also check this

JavaScript Regular Expression Email Validation

Community
  • 1
  • 1
rajesh kakawat
  • 10,826
  • 1
  • 21
  • 40