4.0.0 • Published 4 years ago

ngx-cpf-cnpj v4.0.0

Weekly downloads
87
License
-
Repository
-
Last release
4 years ago

Cpf and Cnpj Mask and Validator for Angular

This is a simple library, containing a mask and a validator for CPF/CNPJ in the same input.

Installation

npm install --save ngx-cpf-cnpj

Quickstart

    import { NgxCpfCnpjModule } from  'ngx-cpf-cnpj';
    (...)
    @NgModule({
    (...)
    imports: [
    NgxCpfCnpjModule]
    (...)
    })

Usage Template Form

Simple Mask:

<input nccCpfCnpjMask  [(ngModel)]="test" >

Mask and Validator:

 <input  name="cpfCnpj"  type="text"  nccCpfCnpjValidator  name="cpfCnpj"  #cpfCnpjv="ngModel"  nccCpfCnpjMask  [(ngModel)]="teste"  >

Form Exemple:

<form  (submit)="submitTest()"  #testForm="ngForm">
    <input  name="cpfCnpj"  type="text"  nccCpfCnpjValidator  name="cpfCnpj"  #cpfCnpjv="ngModel"  nccCpfCnpjMask  [(ngModel)]="teste"  >
    <button  type="submit">Submit</button>
    <div  padding  *ngIf="testForm.submitted && cpfCnpjv?.invalid"  class="error">
        Cpf/Cnpj Inválido
    </div>
</form>

Usage Reactive Form:

export class AppComponent implements OnInit {
  private formTest: FormGroup;

  constructor(private fb: FormBuilder) {}

  ngOnInit() {
    this.formTest = this.fb.group({
      cpfCnpj: ["", CpfCnpjValidator.validate]
    });
  }

  submitReactive() {
    console.log("submit", this.formTest.value.cpfCnpj);
  }
}
<form (submit)="submitReactive(formTest)" [formGroup]="formTest">
  <input
    id="cpfCnpjReactive"
    name="cpfCnpj"
    formControlName="cpfCnpj"
    type="text"
    nccCpfCnpjMask
  />
  <button type="submit">Submit</button>
  <div *ngIf="formTest.controls.cpfCnpj.errors">
    Cpf/Cnpj Inválido
  </div>
</form>
1.0.0

4 years ago

4.0.0

4 years ago

3.0.2

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.0.0

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

5 years ago

1.0.1

5 years ago

0.0.1

5 years ago