fn
isValidCardNumber
v0.0.5Whether value is a complete, valid payment-card number: it passes
the Luhn checksum (luhn from @robonen/encoding) AND its digit length matches
the detected findCardBrand brand (or the 12–19 digit ISO/IEC 7812 range
when the brand is unknown). For the bare checksum, use luhn directly.
Example
ts
isValidCardNumber('4111 1111 1111 1111'); // true
isValidCardNumber('4111 1111 1111'); // false (wrong length)Signature
ts
declare function isValidCardNumber(value: string, brands?: readonly CardBrand[]): boolean;Parameters
| Parameter | Type | Description |
|---|---|---|
value | string | The card number (separators allowed) |
brands? | readonly CardBrand[] | The brand list |
Returns
booleanWhether the number is structurally valid