Coder Social home page Coder Social logo

wking / angular-validation-match Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thesharpieone/angular-validation-match

1.0 3.0 0.0 106 KB

Checks if one input matches another. Useful for confirming passwords, emails, or anything.

License: MIT License

JavaScript 100.00%

angular-validation-match's Introduction

Build Status Code Climate Test Coverage Coverage Status Dependency Status devDependency Status

Angular Validation: Match

Checks if one input matches another. Useful for confirming passwords, emails, or anything.

The match attribute should be set equal to the ng-model value of the field to match.

Demo: http://jsfiddle.net/TheSharpieOne/q300sku2/

Installation

bower install angular-validation-match

Then add validation.match to your angular dependencies

Note: For angular 1.2 or lower use bower install angular-validation-match#1.3

Usage

Simple Property Example

Password: <input ng-model="password" type="password" />
Confirm: <input ng-model="passwordConfirm" type="password" match="password" />

Object Property Example

Password: <input ng-model="user.password" type="password" />
Confirm: <input ng-model="user.passwordConfirm" type="password" match="user.password" />

Case insensitive (caseless) Example

Password: <input ng-model="user.password" type="password" />
Confirm: <input ng-model="user.passwordConfirm" type="password" match="user.password" match-caseless="true" />

match-caseless can accept a scoped variable to allow the matching to be toggle-able between case insensitive and case sensitive.

Display Custom Error
If your form and field both are named, you can access the validation result to show/hide messages.

<form name="myForm">
      Password: <input ng-model="user.password" type="password" name="passwordName" />
      Confirm: <input ng-model="user.passwordConfirm" type="password" match="user.password" name="myConfirmField" />
      <div ng-show="myForm.myConfirmField.$error.match">Fields do not match!</div>
</form>

Validate Against the $viewValue shown in the input
The internal value ($modelValue) can differ from the external value ($viewValue) as appears in the input field shown to the user. If your form and field both are named, you can validate against value displayed in the field, even if the field is invalid.

<form name="myForm">
    Password: <input ng-model="user.password" type="password" name="myPasswordField" />
    Confirm: <input ng-model="user.passwordConfirm" type="password" match="myForm.myPasswordField" name="myConfirmField" />
</form>

Note: $viewValues are specific to fields/elements, not models. Different fields with the same ngModel and have different $viewValues. Becuase of this, you need to use the form directive (assigning a name to a form tag) in combination with the specific field's name attribute to specific which field/element you want to match in particular.

angular-validation-match's People

Stargazers

 avatar

Watchers

 avatar  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.