我有JavaScript的正则表达式this:为什么这个特定的正则表达式在JavaScript中不起作用?
var myString="[email protected]";
var mailValidator = new RegExp("\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
if (!mailValidator.test(myString))
{
alert("incorrect");
}
,但它不应该警惕 “不正确” 与[email protected]
。
它应该返回“不正确”aaaaaa.com
而不是(例如)。
我在哪里错了?
如果你想使用正则表达式验证电子邮件地址,使用[这一个,而不是(http://stackoverflow.com/questions/46155/validate-email-address-in -javascript)。 –
[为什么这个JavaScript的正则表达式不起作用?]的可能重复(http://stackoverflow.com/questions/7427731/why-this-javascript-regex-doesnt-work) – Jerry