Data::Transpose::Validator::CreditCard - Validator for CC numbers
From inside Data::Transpose::Validator
$dtv->prepare( cc_number => { validator => { class => 'CreditCard', options => { types => [ "visa card", "mastercard", "American Express card", "Discover card" ], country => 'DE', }, }, required => 1, }, cc_month => { validator => { class => 'NumericRange', options => { min => 1, max => 12, }, }, required => 1, }, cc_year => { validator => { class => 'NumericRange', options => { min => 2013, max => 2023, }, }, required => 1, } ); my $form = { cc_number => ' 4111111111111111 ', cc_month => '12', cc_year => '2014', }; my $clean = $dtv->transpose($form); ok($clean, "validation ok");
Or, as stand-alone module:
my $v = Data::Transpose::Validator::CreditCard->new(country => 'DE', types => ["visa card", "mastercard"]); ok($v->is_valid("4111111111111111")); ok(!$v->is_valid("4111111111111112"));
This module wraps Business::CreditCard to validate a credit card number.
Constructor. The options as the following:
Two letters country code (for card type detection purposes). Defaults to "US" (as per Business::CreditCard defaults).
List of accepted CC type. The string is case insensitive, but must match the following recognized types. It's unclear how much reliable is this, so use with caution. Recognized types:
American Express card BankCard China Union Pay Discover card Isracard JCB Laser MasterCard Solo Switch VISA card
Check with ref if the argument is a valid credit card and return it on success (without whitespace).
ref
For testing (and validation) purposes, this method returns an hashref with the test credit card numbers for each provider (as listed by Business::CreditCard::cardtype()).
To install Data::Transpose, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Transpose
CPAN shell
perl -MCPAN -e shell install Data::Transpose
For more information on module installation, please visit the detailed CPAN module installation guide.