nice-validator 0,0 editorconfig travis-ci Bower gulp npm

Simple, smart and pleasant validation solution.

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.

Related Repositories

nice-validator

nice-validator

Simple, smart and pleasant validation solution. ...

grunt-nice-package

grunt-nice-package

Opinionated package.json validator ...

class-transformer-validator

class-transformer-validator

A simple plugin for class-transformer and class-validator which combines them in a nice and programmer-friendly API. ...


Top Contributors

niceue xiegang bitdeli-chef PeterDaveHello gitter-badger

Dependencies

package version
jquery >=1.7
dev gulp ^3.9.1
gulp-eslint ^2.1.0
gulp-insert ^0.5.0
gulp-mocha-phantomjs ^0.11.0
gulp-rename ^1.2.2
gulp-stylus ^2.5.0
gulp-uglify ^1.5.4
gulp-zip ^3.2.0

Releases

-   1.0.7 zip tar
-   1.0.6 zip tar
-   1.0.5 zip tar
-   1.0.4 zip tar
-   1.0.3 zip tar
-   1.0.1 zip tar
-   1.0.0 zip tar
-   0.10.11 zip tar
-   0.10.9 zip tar
-   0.10.8 zip tar
-   0.10.5 zip tar
-   0.10.4 zip tar
-   0.10.3 zip tar
-   0.10.2 zip tar
-   0.10.0 zip tar
-   0.9.0 zip tar
-   0.8.1 zip tar
-   0.8.0 zip tar
-   0.7.3 zip tar
-   0.7.2 zip tar
-   0.6.8 zip tar
-   0.6.6 zip tar
-   0.6.2 zip tar
-   0.6.1 zip tar
-   0.5.1 zip tar
-   0.5.0 zip tar
-   0.4.1 zip tar
-   0.4.0 zip tar
-   0.2.1 zip tar
-   0.2.0 zip tar