Angular directives for formatting and validating credit card inputs
npm install angular-credit-cardsA set of Angular directives for constructing credit card payment forms. Uses creditcards to parse and validate inputs. Pairs well with angular-stripe or any other payments backend. Try it!
bash
use npm
$ npm install angular-credit-cards
or bower
$ bower install angular-credit-cards
`Setup
Include
'angular-credit-cards' in your module's dependencies:`js
// node module exports the string 'angular-credit-cards' for convenience
angular.module('myApp', [
require('angular-credit-cards')
]);
// otherwise, include the code first then the module name
angular.module('myApp', [
'credit-cards'
]);
`If you'd like to use the creditcards API directly, you can inject the service as
creditcards.API
With the exception of
ccExp, all directives require ngModel on their elements. While designed to be used together, all directives except ccExp can be used completely independently.All directives apply a numeric input pattern so that mobile browsers use a modified version of the enlarged telephone keypad. You should use
type="text" for all input elements.
$3
`html
`* Can format your inputs into space-delimited groups (e.g.
4242 4242 4242 4242) by adding the cc-format option
* Strips all punctuation and spaces in the model
* Validates the card against the Luhn algorithm
* Checks whether the card is the type(s) specified in scope property in cc-type (optional)
* Otherwise, checks whether the card matches any valid card type
* Exposes the card type as $ccType on the model controllerIf you're using
cc-format, you'll want to apply the novalidate attribute to your