我在JavaScript中有以下電子郵件驗證正則表達式。它實際上不會返回任何東西,但我認爲它應該(真或假)。如何在JavaScript中使用正則表達式驗證電子郵件地址?
這段代碼有什麼問題?
function isEmail(aa){
var testx=/^([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22))*\x40([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d))*$/
return testx.test(aa);
}
<input type="text" name="email" id="email" onChange="isEmail(this.value)">
'return testx.test(aa)'< - variable not string – elclanrs 2013-05-07 10:35:27
你認爲你會保持這個正則表達式嗎?你應該閱讀[this](http://davidcel.is/blog/2012/09/06/stop-validating-email-addresses-with-regex/)。 – 2013-05-07 10:35:30
'onchange =「return isEmail(this.value)」' - 除了我不認爲你可以取消一個onchange事件。如果輸入的值未通過驗證,您希望實際發生什麼? – nnnnnn 2013-05-07 10:37:23