[英]bassistance jQuery Validation throwing errors
Using bassistance.de's jQuery validation plugin, the validation do not always work, especially when an input that's initially been validated has its values removed. 使用bassistance.de的jQuery验证插件,验证并不总是有效,尤其是在最初验证了输入的值被删除的情况下。
The form will pass the validation test with the missing input, and the following error is also seen in the JS console. 表单将通过缺少输入的验证测试,并且在JS控制台中还会看到以下错误。
Error 错误
jQuery lib jQuery库
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/additional-methods.js"></script>
Form 形成
<form id="payment-form" class="payment-form" method="POST" action="/checkout-process">
<fieldset>
<legend>Customer Info</legend>
<label>Full Name</label>
<input type="text" name="first_name" placeholder="First Name">
<input type="text" name="last_name" placeholder="Last Name">
<label>Email</label>
<input type="text" name="email" placeholder="me@email.com">
<label>Phone</label>
<input type="text" name="phone" placeholder="Phone">
</fieldset>
</form>
JS JS
$(function($) {
// Validation
$('#payment-form').validate({
rules: {
first_name: "required",
last_name: "required",
email: {
required: true,
email: true
},
phone: {
required: true,
phone: true
}
},
errorClass: 'alert alert-error'
});
});
The problem is with the rule phone
, there is no validation method called phone
. 问题在于规则phone
,没有称为phone
验证方法。
If you include the additional-methods.js , then you can have phone validation rules like phoneUS
, phoneUK
, mobileUK
, phoneNL
etc 如果包含phoneUS
-methods.js ,则可以具有电话验证规则,例如phoneUS
, phoneUK
, mobileUK
, phoneNL
等
Ex: 例如:
$(function($) {
// Validation
$('#payment-form').validate({
rules: {
first_name: "required",
last_name: "required",
email: {
required: true,
email: true
},
phone: {
required: true,
phoneUS: true
}
},
errorClass: 'alert alert-error'
});
});
If none of these matches your requirement, then you may have to write a custom rule 如果这些都不符合您的要求,那么您可能必须编写自定义规则
请检查链接,并确保它可以解析确切的网址。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.