├── .gitignore ├── Gruntfile.js ├── LICENSE.md ├── README.md ├── bower.json ├── dist └── angular-validate.min.js ├── index.js ├── package.json └── src └── angular-validate.js /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | node_modules/ 3 | bower_components/ 4 | -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | module.exports = function (grunt) { 2 | grunt.initConfig({ 3 | uglify: { 4 | dist: { 5 | files: { 6 | 'dist/angular-validate.min.js': ['src/angular-validate.js'] 7 | } 8 | } 9 | } 10 | }); 11 | 12 | grunt.loadNpmTasks('grunt-contrib-uglify'); 13 | 14 | grunt.registerTask('dist', ['uglify:dist']); 15 | }; 16 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Jan-Paul Kleemans 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Angular Validate 2 | 3 | [](https://github.com/jpkleemans/angular-validate/releases/latest) 4 | [](https://github.com/jpkleemans/angular-validate/blob/master/LICENSE.md) 5 | 6 | Painless form validation for [AngularJS](https://github.com/angular/angular.js). Powered by the [jQuery Validation Plugin](https://github.com/jzaefferer/jquery-validation). 7 | 8 | DEMO 9 | 10 | ## Table of contents 11 | 12 | 1. [Installation](#installation) 13 | 2. [Usage](#usage) 14 | 3. [Built-in validation rules](#built-in-validation-rules) 15 | 4. [Configuration](#configuration) 16 | 17 | ## Installation 18 | 19 | Download Angular Validate: 20 | 21 | 22 | - With NPM: 23 | 24 | ```sh 25 | $ npm install jpkleemans-angular-validate 26 | ``` 27 | 28 | - With Bower: 29 | 30 | ```sh 31 | $ bower install jpkleemans-angular-validate 32 | ``` 33 | 34 | - With Git: 35 | 36 | ```sh 37 | $ git clone https://github.com/jpkleemans/angular-validate.git 38 | ``` 39 | 40 | - By manually downloading the [latest release](https://github.com/jpkleemans/angular-validate/releases/latest). 41 | 42 | > When using one of the last two methods make sure you also download the latest release of the [jQuery Validation Plugin](https://github.com/jzaefferer/jquery-validation). 43 | 44 | Include both `jquery.validate.min.js` and `angular-validate.min.js` in your HTML page: 45 | 46 | ```html 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | ``` 55 | 56 | Inject the `ngValidate` module as a dependency into your Angular application: 57 | 58 | ```js 59 | angular.module('myApp', ['ngValidate']); 60 | ``` 61 | 62 | ## Usage 63 | 64 | Add the ng-validate directive to your form and pass the validation options as value: 65 | 66 | ```html 67 |
71 | ``` 72 | 73 | #### Set validation options 74 | 75 | Then set the validation options in your controller: 76 | 77 | ```js 78 | $scope.validationOptions = { 79 | rules: { 80 | email: { 81 | required: true, 82 | email: true 83 | }, 84 | password: { 85 | required: true, 86 | minlength: 6 87 | } 88 | }, 89 | messages: { 90 | email: { 91 | required: "We need your email address to contact you", 92 | email: "Your email address must be in the format of name@domain.com" 93 | }, 94 | password: { 95 | required: "You must enter a password", 96 | minlength: "Your password must have a minimum length of 6 characters" 97 | } 98 | } 99 | } 100 | ``` 101 | 102 | Or (for simple forms) insert the options directly without using a controller: 103 | 104 | ```html 105 |