import { Component } from '@angular/core';
import { WrInput } from 'ngwr/input';
import { WrValidators } from 'ngwr/validators';
@Component({ imports: [WrInput] })
export class MyComponent {}cardNumber
Check a card number: 13 to 19 digits with a valid Luhn checksum.
Installation
Import the class, and @use the entry point in your global styles: without it the component renders unstyled.
Live demo
Try the test number 4242 4242 4242 4242.
Usage
import { FormControl } from '@angular/forms';
import { WrValidators } from 'ngwr/validators';
const card = new FormControl('', [WrValidators.cardNumber]);
card.setValue('4242 4242 4242 4242'); // valid
card.setValue('1234567890123456'); // { cardNumber: true }API
| Name | Description | Type | Default |
|---|---|---|---|
signature | Add it to a validators array. | ValidatorFn | — |
accepted | 13 to 19 digits, valid Luhn checksum. Spaces and dashes are ignored. | string | — |
error key | On failure: { cardNumber: true }. Empty value passes. | { cardNumber: true } | — |