gpt4 book ai didi

jQuery - 实时验证插件

转载 作者:行者123 更新时间:2023-12-03 22:25:07 27 4
gpt4 key购买 nike

我正在寻找一个 jQuery 插件,它可以在按下按键时以及在失去焦点(文本框)后进行验证。

我目前正在使用jVal - jQuery Form Field Validation Plugin 。效果非常好。我遇到的唯一问题是我只能使用通用错误消息。

例如: 我需要一个 2 到 5 个字符的字符串。如果它太短,我想显示一条错误消息,指示它很短,如果它太长,我也想显示一条错误消息。我知道我可以显示一条错误消息,要求字符串长度在 2 到 5 个字符之间。 正在进行的验证更加复杂。

其他验证器的任何想法或我如何使用此插件来显示独特的错误消息。

<小时/>

编辑:

验证工具需要防止特定的字母或数字,并且不需要表单。

谢谢

最佳答案

这个看起来符合您的描述:

这是从演示源复制的代码片段:

// validate signup form on keyup and submit
$("#signupForm").validate({
rules: {
firstname: "required",
lastname: "required",
username: {
required: true,
minlength: 2
},
password: {
required: true,
minlength: 5
},
confirm_password: {
required: true,
minlength: 5,
equalTo: "#password"
},
email: {
required: true,
email: true
},
topic: {
required: "#newsletter:checked",
minlength: 2
},
agree: "required"
},
messages: {
firstname: "Please enter your firstname",
lastname: "Please enter your lastname",
username: {
required: "Please enter a username",
minlength: "Your username must consist of at least 2 characters"
},
password: {
required: "Please provide a password",
minlength: "Your password must be at least 5 characters long"
},
confirm_password: {
required: "Please provide a password",
minlength: "Your password must be at least 5 characters long",
equalTo: "Please enter the same password as above"
},
email: "Please enter a valid email address",
agree: "Please accept our policy"
}
});

关于jQuery - 实时验证插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/209127/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com