插件 jQuery.nice Validator 中文API文档

🌙
手机阅读
本文目录结构

插件 jQuery.nice Validator 中文API文档 https://github.com/niceue/validator

nice-validator

Build Status Downloads Version License MIT

Simple, smart and pleasant validation solution.

Download the latest release or install package via npm or bower

$ npm install nice-validator
$ bower install nice-validator

Getting started

1. Include jQuery 1.7+

2. Include nice-validator

width <script> tag:

<script src="path/to/nice-validator/jquery.validator.min.js?local=en"></script>

via webpack

require('nice-validator')
require('nice-validator/local/zh-CN')

via module loader Requirejs:

requirejs.config({
    paths: {
        jquery: 'http://cdn.jsdelivr.net/jquery/1.12.3/jquery.min',
        validator: 'path/to/nice-validator/local/en'
    },
    shim: {
        validator: ['path/to/nice-validator/jquery.validator.js?css']
    }
});

require(['validator']);

3. Config rules

<form id="form1">
<input type="text" name="field1" data-rule="required;email;remote(checkEmail.php)">
<input type="text" name="field2" data-rule="required;length(6~16)">
<input type="text" name="field3" data-rule="match(field2)">
<input type="text" name="field4" data-rule="range(0~100)" id="field4">
<input type="text" name="field5" data-rule="required(#field4:filled)">
<input type="text" name="field6" data-rule="required; mobile|email;" data-msg="Please fill mobile or email">
<input type="text" name="field7"
    data-rule="required; !digits; length(6~)"
    data-msg-digits="Please not fill pure digits"
    data-msg-length="Please fill at least {1} characters.">
<input type="checkbox" name="field8" data-rule="checked">
... yadda yadda ...
</form>

It has started to work when you use native submitting.

4. Handle submit (Optional)

$("#form1").on('valid.form', function(){
    // You can do something, then submit form by native
    // this.submit();
    // or submit form by ajax
    $.post("path/to/server", $(this).serialize())
        .done(function(d){
            // do something
        });
});

Documention

Browser Support

  • IE6+
  • Chrome
  • Safari 4+
  • Firefox 9+
  • Opera

Bugs / Contributions

  • Report a bug
  • To contribute or send an idea, github message me or fork the project

Build

Install dependencies:

$ npm install -g gulp
$ npm install

Run test and build:

$ gulp

License

nice-validator is available under the terms of the MIT License.

AXIHE / 精选资源

浏览全部教程

面试题

学习网站

前端培训
自己甄别

前端书籍

关于朱安邦

我叫 朱安邦,阿西河的站长,在杭州。

以前是一名平面设计师,后来开始接接触前端开发,主要研究前端技术中的JS方向。

业余时间我喜欢分享和交流自己的技术,欢迎大家关注我的 Bilibili

关注我: Github / 知乎

于2021年离开前端领域,目前重心放在研究区块链上面了

我叫朱安邦,阿西河的站长

目前在杭州从事区块链周边的开发工作,机械专业,以前从事平面设计工作。

2014年底脱产在老家自学6个月的前端技术,自学期间几乎从未出过家门,最终找到了满意的前端工作。更多>

于2021年离开前端领域,目前从事区块链方面工作了