ValidatorOptional

cvc

Check a card security code: 3 digits, or 4 for Amex.

Installation

Import the class, and @use the entry point in your global styles: without it the component renders unstyled.

import { Component } from '@angular/core';
import { WrInput } from 'ngwr/input';
import { WrValidators } from 'ngwr/validators';

@Component({ imports: [WrInput] })
export class MyComponent {}

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

API

NameDescriptionTypeDefault
signatureCall it with the digit count.(length?: number) => ValidatorFn—
lengthExact digit count: 3, or 4 for Amex.number3
error keyOn failure: { cvc: { length } }, the count it wanted. Empty value passes.{ cvc: { length: number } }—

See also