-1

I'm using this simple regexp to validate an email in query, but it gives a syntax error because of the '@'.

var regexEmail = '^[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}$';

Is there a work around for this problem?

EDIT

Like I said, its the use of the character '@' that causes the problem. When delete it from te expression, the syntax error disappears. Maybe it's because I'm using it in a CSHTML page, whenever I type in the '@', it turns yellow.

Bouss
  • 205
  • 2
  • 9
  • 20
  • What syntax error does it output? – Amal Murali Aug 30 '14 at 17:14
  • you don't need to give `\b` at the start or at the end. – Avinash Raj Aug 30 '14 at 17:14
  • It shows this output error: "[" is not valid at the start of a code block. Only identifiers, keywords, comments, "(" and "{" are valid. – Bouss Aug 30 '14 at 17:29
  • Seems to work okay here: http://jsfiddle.net/1bL9pgoc/ What's the rest of your code? – Stuart Miller Aug 30 '14 at 17:31
  • I'm using it on a CSHTML page, maybe that got something to do with it – Bouss Aug 30 '14 at 17:36
  • Is the error in the javascript console or shown in the browser content window? If it's in the browser window definitely something else. Sounds like the server is trying to evaluate the code as something else. – Stuart Miller Aug 30 '14 at 17:40
  • http://regex101.com/r/bJ6rZ5/2 Only input strings of these type are accepted.Are you sure your are not giving small alphabets in your mail id? – vks Aug 30 '14 at 17:46
  • possible duplicate of [Using a regular expression to validate an email address](http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address) –  Aug 30 '14 at 18:06

1 Answers1

0

Try this :-

var pattern=\"^[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}$\";

Tushar Raj
  • 761
  • 6
  • 20