Why this returns false instead of true.
function doit(expression) {
var regex = new RegExp(expression, 'g');
alert(regex.test('mename@memail.com'));
}
doit("/^\w+([-+.\']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/");
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Either format your expression properly:
or pass the expression directly:
The slashes (
/) are not part of the expression, they denote a regex literal. If you use a string containing the expression, you have to omit them and escape every backslash since the backslash is the escape character in strings as well.