Live demo — 3 digits (Visa / MC)
Live demo — 4 digits (Amex)
Usage
import { FormControl } from '@angular/forms';
import { WrValidators } from 'ngwr/validators';
const cvc = new FormControl('', [WrValidators.cvc()]); // 3 digits
const amex = new FormControl('', [WrValidators.cvc(4)]); // 4 digitsWhy ngwr provides this
Pairs with cardNumber — length-aware (3 digits, or 4 for Amex) instead of a brittle pattern.
API
| Name | Description | Type | Default |
|---|---|---|---|
signature | Factory — call with the expected length. | (length?: number) => ValidatorFn | — |
length | Exact digit count. 3 for Visa/MC/Discover, 4 for Amex. | number | 3 |
error key | On failure: { cvc: { length } } — the digit count it wanted, so one message can serve both card families. Empty value passes. | { cvc: { length: number } } | — |