You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 3.2 KiB

4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. # nice-validator
  2. [![Build Status](https://travis-ci.org/niceue/nice-validator.svg)](https://travis-ci.org/niceue/nice-validator)
  3. [![Downloads](https://img.shields.io/github/downloads/niceue/nice-validator/total.svg)](https://github.com/niceue/nice-validator/releases)
  4. [![Version](https://img.shields.io/npm/v/nice-validator.svg)](https://www.npmjs.com/package/nice-validator)
  5. [![License MIT](https://img.shields.io/badge/license-MIT-blue.svg)](http://niceue.com/licenses/MIT-LICENSE.txt)
  6. Simple, smart and pleasant validation solution.
  7. [Download](https://github.com/niceue/nice-validator/releases) the latest release
  8. or install package via [npm](https://www.npmjs.com/) or [bower](http://bower.io/)
  9. ```bash
  10. $ npm install nice-validator
  11. ```
  12. ```bash
  13. $ bower install nice-validator
  14. ```
  15. ## Getting started
  16. #### 1. Include [jQuery 1.7+](http://jquery.com)
  17. #### 2. Include nice-validator
  18. width `<script>` tag:
  19. ```html
  20. <script src="path/to/nice-validator/jquery.validator.min.js?local=en"></script>
  21. ```
  22. via [webpack](http://webpack.github.io/)
  23. ```javascript
  24. require('nice-validator')
  25. require('nice-validator/local/zh-CN')
  26. ```
  27. via module loader [Requirejs](http://requirejs.org/):
  28. ```javascript
  29. requirejs.config({
  30. paths: {
  31. jquery: 'http://cdn.jsdelivr.net/jquery/1.12.3/jquery.min',
  32. validator: 'path/to/nice-validator/local/en'
  33. },
  34. shim: {
  35. validator: ['path/to/nice-validator/jquery.validator.js?css']
  36. }
  37. });
  38. require(['validator']);
  39. ```
  40. #### 3. Config rules
  41. ```html
  42. <form id="form1">
  43. <input type="text" name="field1" data-rule="required;email;remote(checkEmail.php)">
  44. <input type="text" name="field2" data-rule="required;length(6~16)">
  45. <input type="text" name="field3" data-rule="match(field2)">
  46. <input type="text" name="field4" data-rule="range(0~100)" id="field4">
  47. <input type="text" name="field5" data-rule="required(#field4:filled)">
  48. <input type="text" name="field6" data-rule="required; mobile|email;" data-msg="Please fill mobile or email">
  49. <input type="text" name="field7"
  50. data-rule="required; !digits; length(6~)"
  51. data-msg-digits="Please not fill pure digits"
  52. data-msg-length="Please fill at least {1} characters.">
  53. <input type="checkbox" name="field8" data-rule="checked">
  54. ... yadda yadda ...
  55. </form>
  56. ```
  57. It has started to work when you use native submitting.
  58. #### 4. Handle submit (Optional)
  59. ```javascript
  60. $("#form1").on('valid.form', function(){
  61. // You can do something, then submit form by native
  62. // this.submit();
  63. // or submit form by ajax
  64. $.post("path/to/server", $(this).serialize())
  65. .done(function(d){
  66. // do something
  67. });
  68. });
  69. ```
  70. ## Documention
  71. - [English](https://github.com/niceue/nice-validator/wiki/Getting-Started)
  72. - [简体中文](http://validator.niceue.com/)
  73. ## Browser Support
  74. * IE6+
  75. * Chrome
  76. * Safari 4+
  77. * Firefox 9+
  78. * Opera
  79. ## Bugs / Contributions
  80. - [Report a bug](https://github.com/niceue/nice-validator/issues)
  81. - To contribute or send an idea, github message me or fork the project
  82. ## Build
  83. Install dependencies:
  84. ```bash
  85. $ npm install -g gulp
  86. $ npm install
  87. ```
  88. Run test and build:
  89. ```bash
  90. $ gulp
  91. ```
  92. ## License
  93. nice-validator is available under the terms of the [MIT License](http://niceue.com/licenses/MIT-LICENSE.txt).