@ng-validators/ng-validators
TypeScript icon, indicating that this package has built-in type declarations

0.12.1 • Public • Published

npm version Build Status

Description

This repository contains native angular forms validators for both template driven and reactive forms.

Table of contents

Getting started

Install library

using npm

npm install @ng-validators/ng-validators --save 

using yarn

yarn add @ng-validators/ng-validators

Usage in reactive forms.

Import only validators you need for you form.

import { greaterThan } from '@ng-validators/ng-validators';

this.formBuilder.group({
    age: ['', greaterThan(18)]
});

Usage in template driven forms.

Import NgValidatorsModule @NgModule declarations.

import { NgValidatorsModule } from '@ng-validators/ng-validators';

@NgModule({
    imports: [NgValidatorsModule]
})
export class AppModule {
}

Now you can use validator directive in HTML template

<input class="form-control" type="text" ngModel name="gt" gt="10"/>

Validators

Angular built-in validators

  • [x] required
  • [x] minlength
  • [x] maxlength
  • [x] pattern

Custom validators

  • [x] rangeLength
  • [x] min
  • [x] gt
  • [x] gte
  • [x] max
  • [x] lt
  • [x] lte
  • [x] range
  • [x] digits
  • [x] number
  • [x] url
  • [x] email
  • [x] date
  • [x] minDate
  • [x] maxDate
  • [x] dateISO
  • [x] creditCard
  • [x] json
  • [x] base64
  • [x] uuid
  • [x] equal
  • [x] notEqual
  • [x] equalTo
  • [x] notEqualTo
  • [ ] Your validator can be here. PR is welcome :)

Contributing

Contributions are welcome. You can start by looking at issues with label Help wanted or creating new Issue with proposal or bug report. If you need validator but it is not listed here, you can submit PR with your validator.

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i @ng-validators/ng-validators

Weekly Downloads

62

Version

0.12.1

License

MIT

Unpacked Size

448 kB

Total Files

92

Last publish

Collaborators

  • anjmao