jQuery-实时验证插件 [英] jQuery - Live Validation Plug-ins

查看:95
本文介绍了jQuery-实时验证插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm looking for a plugin for jQuery that can validate as a key is pressed and after it loses focus (text boxes).

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

I'm currently using jVal - jQuery Form Field Validation Plugin. It works pretty good. The only issue I have is that I can only use a generic error message.

例如: 我需要2到5个字符之间的字符串.如果它太短,我想显示一条错误消息,指出它很短,如果它太长,同样.我知道我可能会显示一条错误消息,要求字符串介于2到5个字符之间. 正在执行的验证更加复杂.

For example: I need a string to between 2 and 5 characters. If its too short I would like to display an error message that indicates it to short, equally if its too long. I know I could display an error message that requires the string to between 2 and 5 characters. The validation that is being done is more complicated.

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

Any ideas of other validators or how I could use this plug-in to display unique error messages.

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

The validation tool needs to prevent particular letters or numbers and not require a form.

谢谢

推荐答案

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

This one looks like it would fit your description:

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

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

Here's a snippet of code copied from the source of the demo:

// 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-实时验证插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆