jQuery – 实时验证插件

前端之家收集整理的这篇文章主要介绍了jQuery – 实时验证插件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在寻找一个jQuery的插件,可以验证一个键被按下后,它失去焦点(文本框).

我目前正在使用jVal – jQuery Form Field Validation Plugin.它的效果非常好.我唯一的问题是我只能使用一般的错误信息.

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

任何其他验证器的想法,或者我如何使用这个插件显示唯一的错误消息.

编辑:

验证工具需要防止特定的字母或数字,而不需要表单.

谢谢

解决方法

这一个看起来像适合你的描述:

> jQuery plugin:validation (Homepage)
> demo
> API docs

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

// 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",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"
    }
});
原文链接:https://www.f2er.com/jquery/176436.html

猜你在找的jQuery相关文章