CVV
The CVV rule validates the short security code printed on a payment card, checking that the field contains only digits and falls within the typical 3-to-4-digit length used across card networks (3 digits on Visa, Mastercard, and Discover; 4 digits on American Express). It's meant to be used alongside the Credit Card rule on a checkout form, catching an obviously mistyped or wrong-length security code before the payment is submitted to your processor.
#Directive Code Snippet
<!DOCTYPE html>
<html lang="en">
...
<form (ngSubmit)="onSubmit(form)" #form="ngForm">
<input cvv type="text" name="<name>" [(ngModel)]="<name>" #<name>="ngModel">
</form>
...
</html>
#Chain Rule Code Snippet
<!DOCTYPE html>
<html lang="en">
...
<form (ngSubmit)="onSubmit(form)" #form="ngForm">
<input [Rule]="cvv" type="text" name="<name>" [(ngModel)]="<name>" #<name>="ngModel">
</form>
...
</html>
#Reactive Form Code Snippet
//component.ts
export class ReactiveComponent{
public form !: FormGroup;
constructor(
private fb : FormBuilder,
private rv : ReactiveValidator,
){this.generteForm()}
generteForm(){
this.form = this.fb.group({
<name> : ['',this.rv.map('cvv',<CUSTOM_MESSAGE>)],
})
}
}
//component.html
<!DOCTYPE html>
<html lang="en">
...
<form [formGroup]="form">
<input type="text" name="<name>" formControlName="<name>">
<ng-absolute-validator [formInstance]="form.get(<name>)"></ng-absolute-validator>
</form>
...
</html>