All Projects → jpkleemans → Angular Validate

jpkleemans / Angular Validate

Licence: mit
Painless form validation for AngularJS. Powered by the jQuery Validation Plugin.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Angular Validate

Angular Validation
AngularJS Form Validation made simple
Stars: ✭ 243 (+242.25%)
Mutual labels:  validation, angularjs
Vee Validate
✅ Form Validation for Vue.js
Stars: ✭ 8,820 (+12322.54%)
Mutual labels:  validation, validate
vue-tiny-validate
💯 Tiny Vue Validate Composition
Stars: ✭ 80 (+12.68%)
Mutual labels:  validation, validate
Valdr
A model centric approach to AngularJS form validation
Stars: ✭ 158 (+122.54%)
Mutual labels:  validation, angularjs
Validate
⚔ Go package for data validation and filtering. support Map, Struct, Form data. Go通用的数据验证与过滤库,使用简单,内置大部分常用验证、过滤器,支持自定义验证器、自定义消息、字段翻译。
Stars: ✭ 378 (+432.39%)
Mutual labels:  validation, validate
Php Validate
Lightweight and feature-rich PHP validation and filtering library. Support scene grouping, pre-filtering, array checking, custom validators, custom messages. 轻量且功能丰富的PHP验证、过滤库。支持场景分组,前置过滤,数组检查,自定义验证器,自定义消息。
Stars: ✭ 225 (+216.9%)
Mutual labels:  validation, validate
checker
Golang parameter validation, which can replace go-playground/validator, includes ncluding Cross Field, Map, Slice and Array diving, provides readable,flexible, configurable validation.
Stars: ✭ 62 (-12.68%)
Mutual labels:  validation, validate
python-valid8
Yet another validation lib ;). Provides tools for general-purpose variable validation, function inputs/outputs validation as well as class fields validation. All entry points raise consistent ValidationError including all contextual details, with dynamic inheritance of ValueError/TypeError as appropriate.
Stars: ✭ 24 (-66.2%)
Mutual labels:  validation, validate
Validator.js
String validation
Stars: ✭ 18,842 (+26438.03%)
Mutual labels:  validation, validate
Validate
A simple jQuery plugin to validate forms.
Stars: ✭ 298 (+319.72%)
Mutual labels:  validation, validate
Form Validation.js
The most customizable validation framework for JavaScript.
Stars: ✭ 127 (+78.87%)
Mutual labels:  validation, validate
Nice Validator
Simple, smart and pleasant validation solution.
Stars: ✭ 587 (+726.76%)
Mutual labels:  validation, validate
Bootstrap Validate
A simple Form Validation Library for Bootstrap 3 and Bootstrap 4 not depending on jQuery.
Stars: ✭ 112 (+57.75%)
Mutual labels:  validation, validate
Password Validator
Validates password according to flexible and intuitive specification
Stars: ✭ 224 (+215.49%)
Mutual labels:  validation, validate
fefe
Validate, sanitize and transform values with proper TypeScript types and zero dependencies.
Stars: ✭ 34 (-52.11%)
Mutual labels:  validation, validate
Validator.js
⁉️轻量级的 JavaScript 表单验证,字符串验证。没有依赖,支持 UMD ,~3kb。
Stars: ✭ 486 (+584.51%)
Mutual labels:  validation, validate
Angular Validation
[INACTIVE] Client Side Validation for AngularJS 1. (You should use version > 2 💥)
Stars: ✭ 714 (+905.63%)
Mutual labels:  validation, angularjs
Slimvalidation
A validator for PHP with Respect/Validation
Stars: ✭ 62 (-12.68%)
Mutual labels:  validation
Openapi Spring Webflux Validator
🌱 A friendly kotlin library to validate API endpoints using an OpenApi 3.0 and Swagger 2.0 specification
Stars: ✭ 67 (-5.63%)
Mutual labels:  validation
Fhir.js
Node.JS library for serializing/deserializing FHIR resources between JS/JSON and XML using various node.js XML libraries
Stars: ✭ 61 (-14.08%)
Mutual labels:  validation

Angular Validate

Bower GitHub license

Painless form validation for AngularJS. Powered by the jQuery Validation Plugin.

DEMO

Table of contents

  1. Installation
  2. Usage
  3. Built-in validation rules
  4. Configuration

Installation

Download Angular Validate:

  • With NPM:
$ npm install jpkleemans-angular-validate
  • With Bower:
$ bower install jpkleemans-angular-validate
  • With Git:
$ git clone https://github.com/jpkleemans/angular-validate.git

When using one of the last two methods make sure you also download the latest release of the jQuery Validation Plugin.

Include both jquery.validate.min.js and angular-validate.min.js in your HTML page:

<!-- jQuery scripts -->
<script src="path/to/jquery.min.js"></script>
<script src="path/to/jquery.validate.min.js"></script>

<!-- Angular scripts -->
<script src="path/to/angular.min.js"></script>
<script src="path/to/angular-validate.min.js"></script>

Inject the ngValidate module as a dependency into your Angular application:

angular.module('myApp', ['ngValidate']);

Usage

Add the ng-validate directive to your form and pass the validation options as value:

<form name="registerform" ng-submit="register(registerform)" ng-validate="validationOptions">
    <input type="email" name="email">
    <input type="password" name="password">
</form>

Set validation options

Then set the validation options in your controller:

$scope.validationOptions = {
    rules: {
        email: {
            required: true,
            email: true
        },
        password: {
            required: true,
            minlength: 6
        }
    },
    messages: {
        email: {
            required: "We need your email address to contact you",
            email: "Your email address must be in the format of [email protected]"
        },
        password: {
            required: "You must enter a password",
            minlength: "Your password must have a minimum length of 6 characters"
        }
    }
}

Or (for simple forms) insert the options directly without using a controller:

<form name="simpleform" ng-submit="register(simpleform)" ng-validate="{rules: {name: "required"}}">

For all available options, see: http://jqueryvalidation.org/validate#validate-options

Check form validity

Now you can validate the form by calling validate() on the form instance:

$scope.register = function (form) {
    if(form.validate()) {
        // Form is valid!
    }
}

You can also pass your validation options as the first parameter of validate().

Get number of invalid fields

$window.alert("There are " + form.numberOfInvalids() + " invalid fields.");

Built-in validation rules

A set of standard validation rules is provided by the jQuery Validation Plugin:

  • required – Makes the element required.
  • remote – Requests a resource to check the element for validity.
  • minlength – Makes the element require a given minimum length.
  • maxlength – Makes the element require a given maxmimum length.
  • rangelength – Makes the element require a given value range.
  • min – Makes the element require a given minimum.
  • max – Makes the element require a given maximum.
  • range – Makes the element require a given value range.
  • email – Makes the element require a valid email.
  • url – Makes the element require a valid url.
  • date – Makes the element require a date.
  • dateISO – Makes the element require an ISO date.
  • number – Makes the element require a decimal number.
  • digits – Makes the element require digits only.
  • creditcard – Makes the element require a credit card number.
  • equalTo – Requires the element to be the same as another one.

More info: http://jqueryvalidation.org/documentation/#link-list-of-built-in-validation-methods

Configuration

Angular Validate ships with a $validatorProvider, that you can use to configure default validation options and custom validation rules.

Default validation options

angular.module('myApp')
    .config(function ($validatorProvider) {
        $validatorProvider.setDefaults({
            errorElement: 'span',
            errorClass: 'help-block'
        });
    });

More info: http://jqueryvalidation.org/jQuery.validator.setDefaults

Custom validation rules

angular.module('myApp')
    .config(function ($validatorProvider) {
        $validatorProvider.addMethod("domain", function (value, element) {
            return this.optional(element) || /^http:\/\/mydomain.com/.test(value);
        }, "Please specify the correct domain for your documents");
    });

More info: http://jqueryvalidation.org/jQuery.validator.addMethod

Modify default error messages

angular.module('myApp')
    .config(function ($validatorProvider) {
        $validatorProvider.setDefaultMessages({
            required: "This field is required.",
            remote: "Please fix this field.",
            email: "Please enter a valid email address.",
            url: "Please enter a valid URL.",
            date: "Please enter a valid date.",
            dateISO: "Please enter a valid date (ISO).",
            number: "Please enter a valid number.",
            digits: "Please enter only digits.",
            creditcard: "Please enter a valid credit card number.",
            equalTo: "Please enter the same value again.",
            accept: "Please enter a value with a valid extension.",
            maxlength: $validatorProvider.format("Please enter no more than {0} characters."),
            minlength: $validatorProvider.format("Please enter at least {0} characters."),
            rangelength: $validatorProvider.format("Please enter a value between {0} and {1} characters long."),
            range: $validatorProvider.format("Please enter a value between {0} and {1}."),
            max: $validatorProvider.format("Please enter a value less than or equal to {0}."),
            min: $validatorProvider.format("Please enter a value greater than or equal to {0}.")
        });
    });

More info: http://jqueryvalidation.org/jQuery.validator.format

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].