我正在寻找一个jQuery的插件,可以在按下键并且失去焦点(文本框)后进行验证.
我目前正在使用jVal - jQuery表单字段验证插件.它的效果非常好.我唯一的问题是我只能使用通用错误消息.
例如:我需要一个2到5个字符的字符串.如果它太短我想显示一条错误信息,表明它是短路的,如果它太长也是如此.我知道我可以显示一条错误消息,要求字符串在2到5个字符之间. 正在进行的验证更复杂.
其他验证器的任何想法或我如何使用此插件来显示唯一的错误消息.
编辑:
验证工具需要防止特定的字母或数字,而不需要表格.
谢谢
这个看起来适合您的描述:
jQuery插件:验证(主页)
演示
API文档
这是从演示源复制的一段代码:
// 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" } });