forked from stripe-archive/jquery.payment
Credit Card Number
Omar Shammas edited this page Sep 13, 2013
·
2 revisions
Formats the credit card card number:
- Limits to 16 numbers
- Restricts input to numbers
- Includes a space between every 4 digits
- American Express formatting support
- Adds a class of the card type (i.e. 'visa') to the input
$('input.credit_card_number').formance('format_credit_card_number');
Validates the credit card number:
- Validates numbers
- Validates Luhn algorithm
- Validates length
$('input.credit_card_expiry').formance('validate_credit_card_number');
//examples
$("<input value='4242424242424242' />").formance('validate_credit_card_number'); // true
$("<input value='4242 4242 4242 4242' />").formance('validate_credit_card_number'); // true
$("<input value='4242-4242-4242-4242' />").formance('validate_credit_card_number'); // true
$("<input value='4242' />").formance('validate_credit_card_number'); // false
This field includes a special helper function to retrieve the credit card type. It recognizes
visa
mastercard
discover
amex
dinersclub
maestro
laser
unionpay
The function will return null
if the card type can't be determined.
$.formance.creditCardType('4242 4242 4242 4242') // 'visa'
Make sure to read about the credit card autocomplete recommendations.