Code Monkey home page Code Monkey logo

ember-credit-cards's Introduction

Ember-credit-cards

Build Status

A credit card utility library and form elements. Most of the utilty functions are copied from the jquery.payment lib.

Checkout the demo.

Components

credit-card-form

Full credit card form with validations and formatting.

Attributes:

  • number
  • name
  • month
  • year
  • cvc
  • zipcode
  • zipcodeRequired

Events:

  • on-validate

Example:

//templates/credit-cards/new.hbs

  <div>
    {{ credit-card-form 
       number=attrs.number 
       name=attrs.name 
       month=attrs.month 
       year=attrs.year 
       cvc=attrs.cvc 
       on-validate="validate"
    }}
  </div>

  <button {{action "save"}} {{bind-attr disabled="disabled"}}>
    Save
  </button>
//routes/credit-cards/new.js

import Ember from 'ember';

export default Ember.Route.extend({
  actions: {
    validate: function(bool) {
      this.controller.set('disabled', !bool);
    }
  }
});

input-credit-card-number

Formats credit card number on entry. Discards non-numeric and extra characters. Parses sets number attribute.

Attributes:

  • number

input-credit-card-cvc

Formats cvc number on entry. Discards non-numeric and extra characters. Parses sets cvc attribute.

Attributes:

  • cvc

input-credit-card-expiration

Validates and formats expiration date. Discards non-numeric and extra characters. Parses and sets month, year attributes.

Attributes:

  • month
  • year

input-credit-card-zipcode

Validates and formats zip code. Discards non-numeric and extra characters. Sets zipcode attribute.

Attributes:

  • zipcode

Validations

validateNumber(number)

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

validateCVC(cvc, type)

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

validateExpiration(month, year)

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

validateZipcode(number)

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

ember-credit-cards's People

Contributors

arenoir avatar ember-tomster avatar fed03 avatar odoe avatar pdud avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.