项目作者: justapagamentos

项目描述 :
Angular BR Validators for Reactive Forms
高级语言: TypeScript
项目地址: git://github.com/justapagamentos/jst-ng-validators.git
创建时间: 2019-05-09T13:31:08Z
项目社区:https://github.com/justapagamentos/jst-ng-validators

开源协议:MIT License

下载


David GitHub npm bundle size" class="reference-link">Jst Validators @justa/ng-validators.svg" alt="npm"> David GitHub @justa/ng-validators.svg" alt="npm bundle size">

🚨 This repo has been moved to Justa Angular Library, see the projects folder to get the source code.


Some Angular Reactive Forms custom validators.

Main project to the Justa Reactive Forms custom validators. Go to projects folder to see the package.

Install

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

Install the peerDependecies:

npm install --save moment @brazilian-utils/validators

Examples

Using the validators:

Import ReactiveFormsModule in app.module.ts

Example with CNPJ Validator

  1. import { Component } from "@angular/core";
  2. import { FormGroup, FormControl } from "@angular/forms";
  3. import { jstValidators } from "@justa/ng-validators";
  4. @Component({
  5. selector: "app",
  6. template: require("./app.html")
  7. })
  8. export class AppComponent {
  9. form: FormGroup;
  10. constructor() {
  11. this.form = new FormGroup({
  12. field: new FormControl("", jstValidators.validateCNPJ)
  13. });
  14. }
  15. }

Example on Stackblitz:

Available custom validators

  • validateDate (format: DD/MM/YYYY)
  • validateCNPJ (format: xx.xxx.xxx/xxxx-xx | xxxxxxxxxxxxxx)
  • validateCPF (format: xxx.xxx.xxx-xx | xxxxxxxxxxx)
  • validatePhone (format: (xx)xxxxx-xxxx | (xx)xxxx-xxxx | xxxxxxxxxx)
  • validateURL (format: http[s]://lol.com)

Build (dev only)

Run ng build @justa/validators to build the project. The build artifacts will be stored in the dist/ directory.

To build the package, run ng build @justa/br-validators.

License

MIT

Running (dev only)

Clone this repo, and install all dependencies. To build a new version, run this command:

ng build @justa/br-validators.