@numetalsour/ngx-rut
v1.0.5
Published
Validations, format(onkey) & error
Downloads
12
Maintainers
Readme
Angular 14+ RUT
Validations, format(onkey) & error
Install project with npm
npm i @numetalsour/ngx-rut --save
Usage
...
import { NgxRutModule } from '@numetalsour/ngx-rut';
...
@NgModule({
declarations: [
AppComponent,
],
imports: [
...
NgxRutModule
...
]
})
export class AppModule { }
Usage/Examples
Programmatically
import { NgxRutService, NgxRutValidator } from '@numetalsour/ngx-rut';
constructor(private _NgxRutService: NgxRutService)
const rutDV = '173426593'
const rut = '17342659'
const format = this._NgxRutService.formatRut(rutDV)
console.log({ format }) //17.342.659-3
const validate = this._NgxRutService.validateRut(rutDV)
console.log({ validate }) // true or false
const calculate = this._NgxRutService.calculateDigit(rut)
console.log({ calculate }) //3
Forms
import { NgxRutService, NgxRutValidator } from '@numetalsour/ngx-rut';
import { FormGroup, FormBuilder } from '@angular/forms';
form: FormGroup;
rut: string
constructor(
private _NgxRutService: NgxRutService,
private fb: FormBuilder
) {
this.form = this.fb.group({
rut: ['', [NgxRutValidator.validate]]
})
}
<form [formGroup]="form">
<mat-form-field>
<mat-label>Rut</mat-label>
<input matInput ngxRut formControlName="rut" >
<mat-error *ngIf="form.get('rut').hasError('invalid')">El rut ingresado no es válido</mat-error>
</mat-form-field>
</form>
<input ngxRut [(ngModel)]="rut" >