jquery验证插件Validator

所属分类:输入-验证

 150069  322  查看评论 (13)
分享到微信朋友圈
X
jquery验证插件Validator ie兼容6

使用

包括在头:

<script src="jquery-1.11.0.min.js"></script>
<script src="fm.validator.jquery.js"></script>


插件激活:

默认初始化时,插件将寻找任何形式包含类验证器,将自身添加到表单的提交事件,然后寻找验证器html5数据属性表明什么以及它如何应该验证表单中的元素。但是你也可以手动验证表单,通过运行验证器。验证功能。这里有一个例子:

if (Validator.validate('#someForm')) {
    alert('The form is valid, awesome!');
    return true;
} else {
    alert('The form is NOT valid!');
}


html5数据属性:

下面是一个示例所需的一个文本框和内容需要3至12个字符。

<form method="post" class="validator">
  <input type="text" data-required data-min="3" data-max="12">
</form>


全局选项

全球语言选项,elementErrorClass和语言翻译,可以在全球设置选项。

这里是一个例子。语言设置为丹麦,改变错误的名称类应用于输入元素:

Validator.language = 'da';
Validator.elementErrorClass = 'fejl';



支持验证

属性有效值描述
data-requiredno valueIf this is set, then the input will require some content
data-required-ifelement idIf set to an id of an element, then it will only be required if said element is checked or has the value of data-required-if-value
data-required-if-valueelement valueIf data-required-if is set to an element id, then it will only be required if said element has said value
data-min=0-90-9The minimum length of the input
data-max=0-90-9The maximum length of the input
data-typeemail,url,number,digitsemail are url are self explanatory, number are the characters 0-9+ - . ,digits are the characters 0-9 only
data-error-positionbefore,after,before-{tagname},after-{tagname}By default the error messages will appear before the input element in the DOM, but you can also set it to appear after. If neede then you can also set it t be before or after the closest parent matching the tagname specified after the dash -


密码输入:

AttributeValid valuesDescription
data-requiredno valueIf this is set, then the input will require some content
data-required-ifelement idIf set to an id of an element, then it will only validate if said element is checked or has the value of data-required-if-value
data-required-if-valueelement valueIf data-required-if is set to an element id, then it will only validate if said element has said value
data-min=0-90-9The minimum length of the input
data-max=0-90-9The maximum length of the input
data-matchelement idIf set to an id of another input element, it will match the contents against that element
data-error-positionbefore,after,before-{tagname},after-{tagname}By default the error messages will appear before the input element in the DOM, but you can also set it to appear after. If neede then you can also set it t be before or after the closest parent matching the tagname specified after th


相关插件-验证

jQuery表单提交验证verify

一整套注册验证,可直接用于实际项目中
  验证
 108632  1450

js滑块验证插件slideHuaKuai.js

js滑块验证插件slideHuaKuai.js,简单使用注释全。
  验证
 14524  193

大气简洁的登录注册特效

大气简洁的登录注册特效带注册验证
  验证
 68545  625

滑动验证登录

用户滑动拖拽图片验证登录加注册
  验证
 57354  422

讨论这个项目(13)回答他人问题或分享插件使用方法奖励jQ币 评论用户自律公约

    秋香 0
    2018/8/18 10:46:39
    感谢博主,在你的基础上进行了一些修改,太好用了! 回复
    佐幽ぁぃ 0
    2017/9/5 23:47:19
    $(this).attr('data-required-if') != undefined && $(this).val() == '' && (($(this).attr('data-required-if-value') == undefined && $('#' + $(this).attr('data-required-if')).is(':checked')) || ($(this).attr('data-required-if-value') != undefined && $('#' + $(this).attr('data-required-if')).val() == $(this).attr('data-required-if-value')))

    代码里面这个判断是什么意思

    回复
    yī种思念灬如影随形 0
    2017/7/1 17:45:25
    说你麻痹 0
    2017/5/26 16:34:09
    最后那几行有点多余了 感觉 回复
    Bamboo Gang! 0
    2017/5/5 14:25:10
    长度有限制最大才是9,这是硬伤 回复
    竹墨残水烟花冷 0
    2017/1/10 19:01:00
    required: 'Dette felt skal udfyldes',min: 'Dette felt skal v?re mindst {characters} tegn',max: 'Dette felt skal v?re h?jst {characters} tegn',email: 'Denne email er ugyldig',url: 'Denne webside er ugyldigt',number: 'Kun tal',digits: 'Kun tal'

    这些可以自动换成中文吗    语言输入::中文应该输入什么  

    回复
    竹墨残水烟花冷 0
    2017/1/10 19:01:34

    怎么把提示换成中文

        小山哥伦布1
        2017/7/20 16:20:40

        自己加个对象'cn'对象啊。如果其他语言用不到的可以直接删掉了。

    回复
    沁梦听雪 1
    2016/11/14 10:11:53
    有个小bug ,最大限制字数提示undefined ,是因为data-max写成了data-min,改改就行,不存在“长度有限制最大才是9,这是硬伤”的问题,是他自己不会用
        来去无影0
        2016/12/28 11:12:32

        可以可以

    回复
    TTT 0
    2015/9/22 15:09:25

    个人感觉不错,谢谢分享

        Mr.Thinker0
        2015/12/27 17:12:45
        长度有限制最大才是9,这是硬伤
        ? 心相连思念如雨0
        2016/1/11 11:01:27

        怎么获取jq币 急用

    回复
😃
  • 😀
  • 😉
  • 😥
  • 😵
  • 😫
  • 😘
  • 😡
  • 👍
  • 🌹
  • 👏
  • 🍺
  • 🍉
  • 🌙
  • 💖
  • 💔
😃
  • 😀
  • 😉
  • 😥
  • 😵
  • 😫
  • 😘
  • 😡
  • 👍
  • 🌹
  • 👏
  • 🍺
  • 🍉
  • 🌙
  • 💖
  • 💔
取消回复