Validator

cvc

N digits — typically 3 (Visa/MC/Discover) or 4 (Amex). Empty values pass.

Live demo — 3 digits (Visa / MC)

errors: null

Live demo — 4 digits (Amex)

errors: null

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 digits

Why ngwr provides this

Pairs with cardNumber — length-aware (3 digits, or 4 for Amex) instead of a brittle pattern.

API

NameDescriptionTypeDefault
signatureFactory — call with the expected length.(length?: number) => ValidatorFn
lengthExact digit count. 3 for Visa/MC/Discover, 4 for Amex.number3
error keyOn failure: { cvc: { length } } — the digit count it wanted, so one message can serve both card families. Empty value passes.{ cvc: { length: number } }

See also