A credit card utility library and form elements. Influenced by the jquery.payment lib.
Checkout the demo.
- Ember.js v3.24 or above
- Ember CLI v3.24 or above
- Node.js v12 or above
ember install ember-credit-cards
Full credit card form with validations and formatting.
Arguments:
- number
- name
- month
- year
- cvc
- zipcode
- zipcodeRequired
Events:
- onUpdate
- onValidate
Example:
Formats credit card number on entry. Discards non-numeric and extra characters. Parses sets number attribute.
Attributes:
- number
Formats cvc number on entry. Discards non-numeric and extra characters. Parses sets cvc attribute.
Attributes:
- cvc
Validates and formats expiration date. Discards non-numeric and extra characters. Parses and sets month, year attributes.
Attributes:
- month
- year
Validates and formats zip code. Discards non-numeric and extra characters. Sets zipcode attribute.
Attributes:
- zipcode
Validates a card number:
- Validates numbers
- Validates Luhn algorithm
- Validates length
Example:
import validations from 'ember-credit-cards/utils/validations';
validations.validateNumber('4242 4242 4242 4242'); //=> true
Validates a card CVC:
- Validates number
- Validates length to 4
Example:
import validations from 'ember-credit-cards/utils/validations';
validations.validateCVC('123'); //=> true
validations.validateCVC('123', 'amex'); //=> true
validations.validateCVC('1234', 'amex'); //=> true
validations.validateCVC('12344'); //=> false
Validates a card expiration date:
- Validates numbers
- Validates in the future
- Supports year shorthand
Example:
import validations from 'ember-credit-cards/utils/validations';
validations.validateExpiration('05', '20'); //=> true
validations.validateExpiration('05', '2015'); //=> true
validations.validateExpiration('05', '05'); //=> false
Validates a zip code:
- Validates 5 digit optional + 4 zipcode
Example:
import validations from 'ember-credit-cards/utils/validations';
validations.validateZipcode('94611'); //=> true
validations.validateZipcode('946'); //=> false
validations.validateZipcode('94611-2544'); //=> true
validations.validateZipcode('946112544'); //=> true
validations.validateZipcode('94611-24'); //=> false
You can provide custom labels for localization.
See the Contributing guide for details.
This project is licensed under the MIT License.