fn

luhn

v0.0.1tested

Validate a number string against the Luhn (mod 10) checksum — the check digit used by payment cards, IMEIs, SIM ICCIDs, and more. Non-digits are ignored; an empty input is false.

Example

ts
luhn('4111 1111 1111 1111'); // true
luhn('4111 1111 1111 1112'); // false

Signature

ts
export function luhn(value: string): boolean{ ... }

Parameters

ParameterTypeDescription
valuestringThe number (separators allowed)

Returns

booleanWhether the Luhn checksum passes