我想使用Ben Keen的RSV Jquery插件來驗證通過註冊表單提交的電子郵件地址:只允許用戶提交一個e郵件地址屬於特定的域。我認爲使用插件的reg_exp規則可能是一個解決方案,但我無法讓它工作。 我是一個jquery新手,所以我可能會犯一些非常愚蠢的錯誤:有人能指點我正確的方向嗎?使用RSV jquery插件驗證來自特定域的電子郵件
這裏是我想要使用的代碼,改編自敏銳的演示之一:
<script type="text/javascript">
// a custom onComplete handler to prevent form submits for the demo
function myOnComplete()
{
alert("The form validates! (normally, it would submit the form here).");
return false;
}
var rules = [];
// standard form fields
rules.push("reg_exp,reg_exp_field1,/@mydomain\.tld$/gi,Please enter your valid e-mail (e.g. \"@mydomain\.tld\")");
$(document).ready(function() {
$("#demo_form3").RSV({
onCompleteHandler: myOnComplete,
rules: rules
});
});
</script>
使用上面的代碼,當我提出一個有效的電子郵件地址,即以@結尾的地址mydomain.tld我總是收到警報。我究竟做錯了什麼?
嗨四維,謝謝你指出我的錯誤。當涉及到jQuery/JavaScript我是一個完整的新手,我正在通過試驗和錯誤學習。 Thanx回覆我的問題:-) – kikaweb 2011-08-12 15:24:34