我有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