当前位置:  开发笔记 > 前端 > 正文

jQuery - 实时验证插件

如何解决《jQuery-实时验证插件》经验,为你挑选了1个好方法。

我正在寻找一个jQuery的插件,可以在按下键并且失去焦点(文本框)后进行验证.

我目前正在使用jVal - jQuery表单字段验证插件.它的效果非常好.我唯一的问题是我只能使用通用错误消息.

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

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


编辑:

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

谢谢



1> hasseg..:

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

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"
    }
});

推荐阅读
yzh148448
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有