Reputation: 875
I'm getting a syntax error in this simple javascript code. I just want to check the atring on a pattern. Can any one tell me what is wrong?
var a = '[email protected]';
var pattern = [a-zA-Z0-9_]+[.[a-zA-Z0-9]+]*@[a-zA-Z0-9_]+[.[a-zA-Z]+]+;
console.log('The comparison is ',a.match(pattern));
Thanks.
Upvotes: 1
Views: 308
Reputation: 5103
try
var pattern = /^[a-zA-Z0-9_]+[.[a-zA-Z0-9]+]*@[a-zA-Z0-9_]+[.[a-zA-Z]+]+$/;
Upvotes: 1
Reputation: 18354
Try
var pattern = /[a-zA-Z0-9_]+[.[a-zA-Z0-9]+]*@[a-zA-Z0-9_]+[.[a-zA-Z]+]+/;
Patterns are usually delimited by //
. See RegExp on MDC.
Upvotes: 4
Reputation: 11042
you have no delimiter on the pattern. Have you tried
var pattern = '[a-zA-Z0-9_]+[.[a-zA-Z0-9]+]*@[a-zA-Z0-9_]+[.[a-zA-Z]+]+';
?
Upvotes: 0