我在JavaScript電子郵件驗證有問題的問題, 我寫的代碼類似,對於checkMail我在JavaScript中的電子郵件驗證
//emp.php
<form action="<?php echo $editFormAction; ?>" method="post" name="form2" id="form2" >
<table>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Desired Email-ID:</td>
<td><input type="text" name="emp_email" value="" size="32" onsubmit="checkMail()";/></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> </td>
<td><input type="submit" value="Insert record" onclick="checkMail();"/></td>
</tr>
</table>
</form>
// java的代碼scrit()
<script language="javascript">
function checkMail() {
var email=document.getElementById('emp_email').value;
var mail = email.value;
var reg = new RegExp('^[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*@[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*[\.]{1}(com|ca|net|org|fr|us|qc.ca|gouv.qc.ca)$', 'i');
if(!reg.test(mail) || mail == "")
{
alert("Your email address isn't valid!");
return false;
}
else {
alert("Email address is okay, let's send the form!");
}
}
</script>
PLZ幫我在此先感謝
什麼問題? – Garry 2009-10-01 10:35:52
好吧,它有一個...有趣的正則表達式,將拒絕大量完美的電子郵件地址。 – Quentin 2009-10-01 10:37:27
你可以發佈你的表單的HTML看起來像什麼嗎?正則表達式看起來不錯 – 2009-10-01 10:38:05