使用 RSV jquery 插件验证来自特定域的电子邮件
我正在尝试使用 Ben Keen 的 RSV Jquery 插件来验证通过注册表提交的电子邮件地址:仅允许用户提交属于特定域的电子邮件地址。我认为使用插件的 reg_exp 规则可能是一个解决方案,但我无法让它工作。 我是 jquery 新手,所以我可能犯了一些非常愚蠢的错误:有人能指出我正确的方向吗?
这是我尝试使用的代码,改编自 Keen 的演示之一:
<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 结尾的地址)时,我总是会收到警报。我做错了什么?
I'm trying to use Ben Keen's RSV Jquery plug-in to validate an e-mail address submitted through a registration form: users are only allowed to submit an e-mail address that belongs to a specific domain. I thought that using the plugin's reg_exp rule could be a solution, but I can't get it to work.
I'm a jquery newbie, so I'm probably making some very silly mistake: can someone point me to the right direction?
Here's the code I'm trying to use, adapted from one of Keen's demo:
<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>
Using the code above, when I submit a valid e-mail address, that is an address ending with @mydomain.tld I always get an alert. What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经为很多行代码编写了 RSV。它非常强大。
然而,你用错了它。
不管怎样,你已经用另一种方式解决了你的问题。 :-) 那挺好的。
I have written RSV for many lines of code. It's very powerful.
However, you used it incorrectly.
Whatever, you have solved your problem in another way. :-) that's good.
没关系,经过进一步的研究,我找到了一个更简单的解决方案:遵循
Never mind, after further researche I found a simpler solution: following the advice in this forum thread I used jqueryValidate instead of rsv plug-in and added custom validate method.
I'm posting here my solution, maybe it could be useful for some other jquery newbie like me!