Skip to content
This repository has been archived by the owner on Nov 30, 2019. It is now read-only.

Latest commit

 

History

History
74 lines (46 loc) · 2.07 KB

README.md

File metadata and controls

74 lines (46 loc) · 2.07 KB

Jst Validators npm David GitHub 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

import { Component } from "@angular/core";
import { FormGroup, FormControl } from "@angular/forms";
import { jstValidators } from "@justa/ng-validators";

@Component({
  selector: "app",
  template: require("./app.html")
})
export class AppComponent {
  form: FormGroup;

  constructor() {
    this.form = new FormGroup({
      field: new FormControl("", jstValidators.validateCNPJ)
    });
  }
}

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.