包括在头:
1 2 | <script src="jquery-1.11.0.min.js"></script><script src="fm.validator.jquery.js"></script> |
插件激活:
默认初始化时,插件将寻找任何形式包含类验证器,将自身添加到表单的提交事件,然后寻找验证器html5数据属性表明什么以及它如何应该验证表单中的元素。但是你也可以手动验证表单,通过运行验证器。验证功能。这里有一个例子:
1 2 3 4 5 6 | if (Validator.validate('#someForm')) { alert('The form is valid, awesome!'); return true;} else { alert('The form is NOT valid!');} |
html5数据属性:
下面是一个示例所需的一个文本框和内容需要3至12个字符。
1 2 3 | <form method="post" class="validator"> <input type="text" data-required data-min="3" data-max="12"></form> |
全局选项
全球语言选项,elementErrorClass和语言翻译,可以在全球设置选项。
这里是一个例子。语言设置为丹麦,改变错误的名称类应用于输入元素:
1 2 | Validator.language = 'da';Validator.elementErrorClass = 'fejl'; |
支持验证
| 属性 | 有效值 | 描述 |
|---|---|---|
| data-required | no value | If this is set, then the input will require some content |
| data-required-if | element id | If 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-value | element value | If data-required-if is set to an element id, then it will only be required if said element has said value |
| data-min=0-9 | 0-9 | The minimum length of the input |
| data-max=0-9 | 0-9 | The maximum length of the input |
| data-type | email,url,number,digits | email are url are self explanatory, number are the characters 0-9+ - . ,, digits are the characters 0-9 only |
| data-error-position | before,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 - |
密码输入:
| Attribute | Valid values | Description |
|---|---|---|
| data-required | no value | If this is set, then the input will require some content |
| data-required-if | element id | If 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-value | element value | If data-required-if is set to an element id, then it will only validate if said element has said value |
| data-min=0-9 | 0-9 | The minimum length of the input |
| data-max=0-9 | 0-9 | The maximum length of the input |
| data-match | element id | If set to an id of another input element, it will match the contents against that element |
| data-error-position | before,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 |
特别申明:
本站所有资源都是由网友投稿发布,或转载各大下载站,请自行检测软件的完整性!
本站所有资源仅供学习与参考,请勿用于商业用途,否则产生的一切后果将由您自己承担!
如有侵权请联系我们删除下架,联系方式:lei1294551502@163.com