Card
Validating Cards is rather simple but time consuming task, valid8r Cards validators provides a handful of options to best suit your validation requirements
import valid8r from '@c4code/valid8r';Configuration Options
import valid8r, { CardType } from '@c4code/valid8r';
const card: CardType = {
number: "4762508284613371", // 13-19 Number format
expirationDate: '02/29', // 'MM/YY'
cardHolderName: 'John Smith',
cvv: 933 // 3 digit cvv
}
// The configuration can be defaulted globally
valid8r.card(card, {
safe: false, // boolean
throwErrorsAs: "throw-all", // "throw-first" | "throw-last" | "throw-all",
/*
"throw-first" => Throws or returns the first error encountered,
"throw-last" => Throws or returns the last error encountered,
"throw-all" => Throws or returns all errors in a Array of string
*/
}); // the second argument is optionalimport valid8r from '@c4code/valid8r';
const card = {
number: "4762508284613371", // 13-19 Number format
expirationDate: '02/29', // 'MM/YY'
cardHolderName: 'John Smith',
cvv: 933 // 3 digit cvv
}
// The configuration can be defaulted globally
valid8r.card(card, {
safe: false, // boolean
throwErrorsAs: "throw-all", // "throw-first" | "throw-last" | "throw-all",
/*
"throw-first" => Throws or returns the first error encountered,
"throw-last" => Throws or returns the last error encountered,
"throw-all" => Throws or returns all errors in a Array of string
*/
}); // the second argument is optionalBasic Usage
Safe handling
Error Messages
Error Message Options
Last updated