Socket
Socket
Sign inDemoInstall

angular.validators

Package Overview
Dependencies
0
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    angular.validators

[![npm version](https://badge.fury.io/js/angular.validators.svg)](http://badge.fury.io/js/angular.validators) [![Bower version](https://badge.fury.io/bo/angular.validators.svg)](http://badge.fury.io/bo/angular.validators) [![Build Status](https://travis-c


Version published
Weekly downloads
338
increased by23.36%
Maintainers
1
Install size
132 kB
Created
Weekly downloads
 

Changelog

Source

v4.2.1

It's been a long time, updated to version 4.2.1

Readme

Source

npm version Bower version Build Status

angular.validators

Angular validation directives using validator.js

Contents

Install

$ bower install angular.validators

Include the module in your dependencies

angular.module('myProject',[
    'angular.validators'
])

Supported functions

Currently the following functions are supported.

DirectiveDescriptionArguments
containscheck if the string contains the seedstring
equalscheck if the string matches the comparison.string
is-aftercheck if the string is a date that's after the specified date (defaults to now).date
is-alphacheck if the string contains only letters (a-zA-Z).
is-alphanumericcheck if the string contains only letters and numbers.
is-asciicheck if the string contains ASCII chars only.
is-base64check if a string is base64 encoded.
is-beforecheck if the string is a date that's before the specified date (defaults to now).date
is-booleancheck if a string is a boolean
is-credit-cardcheck if the string is a credit card.
is-currencycheck if the string is a valid currency amountas in validator.js isCurrency
is-datecheck if the string is a date.
is-divisible-bycheck if the string is a number that's divisible by anotherInt
is-emailcheck if the string is an email.as in validator.js isEmail
is-fqdncheck if the string is a fully qualified domain name (e.g. domain.com).
is-floatcheck if the string is a float.
is-full-widthcheck if the string contains any full-width chars.
is-half-widthcheck if the string contains any half-width chars.
is-hex-colorcheck if the string is a hexadecimal color.
is-hexadecimalcheck if the string is a hexadecimal number.
is-ipcheck if the string is an IP (version 4 or 6).4, 6
is-isbncheck if the string is an ISBN (version 10 or 13).10, 13
is-isincheck if the string is an ISIN (stock/security identifier)
is-iso8601check if the string is a valid ISO 8601 date.
is-incheck if the string is in a array of allowed values.array e.g ['a','b','c']
is-intcheck if the string is an integer.
is-jsoncheck if the string is valid JSON (note: uses JSON.parse).
is-lowercasecheck if the string is lowercase.
is-mobile-phonecheck if the string is a mobile phone numberzh-CN, en-ZA, en-AU, pt-PT, el-GR. For el-GR landline and mobile phones are validated.
is-mongo-idcheck if the string is a valid hex-encoded representation of a MongoDB ObjectId.
is-multibytecheck if the string contains one or more multibyte chars.
is-nullcheck if the string is null.
is-numericcheck if the string contains only numbers.
is-urlcheck if the string is a URL.
is-uuidcheck if the string is a UUID (version 3, 4 or 5).3, 4, 5
is-uppercasecheck if the string is uppercase.
is-variable-widthcheck if the string contains a mixture of full and half-width chars.
is-surrogate-paircheck if the string contains any surrogate pairs chars.
watch-equalscheck if the string matches the comparison.ngModel

Use

To use a validator simply include the angular directive in an input element.

<form name="form">
  <input type="text" ng-model="value" name="value" is-mongo-id />
</form>

You can use multiple directives at once

<form name="form">
  <input type="text" ng-model="value" name="value" is-alpha is-lowercase />
</form>
Async Validation

As of version 3.41.3 angular validators support async validation. To use async validation first you have to configure the asyncValidatorProvider in your app.js

angular.module('my-project', [
    ...,
    'angular.validators'
])
.config(['asyncValidatorProvier', function(asyncValidatorProvider){
    asyncValidatorProvider
        .baseUrl('http://localhost:1337')
        .endpoint('usernane', '/api/username/{value}')
        ...
}])

Some words on the api: the api must return a JSON object that has an attribute named data and within an other attribute that contains the result. The default name for the attribute is 'valid'. You can change the name of the attribute on the config phase using the 'responseField' function.

The available options for asyncValidatorProvider are the following:

functionargumentsdescriptionexample
baseUrl(string)stringsets the base url for api (helper function).baseUrl('http://localhost:1337')
defaultState(boolean)booleanthe default state of the validator (defaults to false)..defaultState(true)
endpoint(name, url)name: string, url: stringsets an endpoint with an easy to use name.endpoint('username', '/api/account/{value}
httpVerb(verb)verb:stringSets the http verd that the api accepts for async validation, defaults to get.httpVerb('post')
invalidResponse(response)response: stringthe response the api returns if the value is invalid, defaults to 'false'.invalidResponse('false')
minLength(length)length: intthe min length that the view value neeeds to have in order to make a call to the api, defaults to 3.minLength(4)
responseField(field)field: stringchange the name of the field that contains the respone.responseField('valid')
validResponse(response)response: stringthe response the api returns if the value is valid, defaults to 'true'.invalidResponse('true')
wildcard(string)stringasync validators uses a place holder to replace the value on the string of the url, defaults to '{value}'wildcard(':value')

All asyncValidatorProvider return the asyncValidatorProvider instance for easy chaining.

To use the directive simply include it in your html:

<form name='form'>
    <input type='text' ng-model='value' name='value' async-valid='username'>
</form>

You can override some global values from the directive itself like this

attributevaluefunction that overrides
async-default-statestringdefaultState(state)
async-invalid-responsestringinvalidResponse(response)
async-min-lengthint, stringminLength(length)
async-valid-responsestringvalidResponse(response)

** if you have any problems with async-valid create an issue on Github

Validator service

Angular validators exposes validatorjs as an angular service named validator. More on validator.js

Changelog

v4.2.1 - It's been a long time, updated to version 4.2.1

v4.0.6 - reverted back to code from v4.0.2 since v4.0.3 & v4.0.4 where riddled with bugs.

v4.0.5 - reverted back to code from v4.0.2 since v4.0.3 & v4.0.4 where riddled with bugs.

v4.0.4 - DECRECATED use v4.0.6+ instead

v4.0.3 - DECRECATED use v4.0.6_ instead

v4.0.2 - updated to validator.js v4.0.2

v4.0.0 - updated to validator.js v4.0.0 and new directive is-iso8601

v3.41.2 - updated to validator.js v3.41.2 and added support for async validation using the asyncValid directive

v3.41.1 - updated to validator.js v3.41.1

v3.40.1 - updated to validator.js v3.40.1. Deprecated is-phone and changed it to is-mobile-phone to be in parity with validator.js. Added new validators and suppot for optional arguments as in validator.js Major refactoring at tests, removed most of the files and replaced them with a single one.

v3.40.0 - updated to validator.js v3.40.0

v3.39.0 - updated to validator.js v3.39.0

v3.38.0 - updated to validator.js v3.38.0

v3.37.3 - updated package.json and bower.json

v3.37.2 - updated package.json and bower.json

v3.37.1 - updated package.json and bower.json

v3.37.0 - updated to validator.js v3.37.0

v3.35.0 - updated to validator.js v3.35.0

v3.34.0 - updated to validator.js v3.34.0

v3.33.1 - all validators are restricted as attributes now

v3.33.0 - updated to validator.js v3.33.0

v3.30.6 - simplified file structure

v3.30.5 - equals, watchEquals validators. watchEquals can be used for password validation where two fields may change. Currently it must not be used as a circular watch, e.x :

<input type="text" name="test1" ng-model="t.test1" watch-equals='{{t.test2}}'/>
<input type="text" name="test2" ng-model="t.test2" watch-equals='{{t.test1}}'/>

v3.30.4 - isPhone validator with validator.js's locales + Greek landline and mobile validation.

v3.30.3 - new validators and some validation options where possible.

v3.30.0 - version bump to be on par with validator.js

License

Copyright (c) 2015 George Kaimakas gkaimakas@gmail.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Keywords

FAQs

Last updated on 10 Nov 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc