Validator

cardNumber

13–19 digit credit card number with Luhn checksum. Spaces and dashes are stripped before checking. Empty values pass.

Live demo

Use a Stripe test number like 4242 4242 4242 4242.

errors: null

Usage

import { FormControl } from '@angular/forms';
import { WrValidators } from 'ngwr/validators';

const card = new FormControl('', [WrValidators.cardNumber]);

card.setValue('4242 4242 4242 4242'); // Stripe test → valid
card.setValue('1234567890123456');    // bad checksum → { cardNumber: true }

Why ngwr provides this

A Luhn checksum catches mistyped card numbers client-side, before a failed payment round-trip. Angular ships nothing for payments and pulling a payments SDK for one check is overkill.

API

NameDescriptionTypeDefault
signatureStatic — drop into a validators array.ValidatorFn
accepted13–19 digits with valid Luhn checksum. Spaces and dashes are stripped before checking.string
error keyOn failure: { cardNumber: true }. Empty value passes.{ cardNumber: true }

See also