GithubHelp home page GithubHelp logo

hhy5277 / nice-validator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from niceue/nice-validator

0.0 2.0 0.0 1.8 MB

Simple, smart and pleasant validation solution.

Home Page: http://validator.niceue.com/

JavaScript 96.42% CSS 2.12% Smarty 0.97% HTML 0.49%

nice-validator's Introduction

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.

nice-validator's People

Contributors

bitdeli-chef avatar gitter-badger avatar larry4xie avatar niceue avatar peterdavehello avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.