Code Monkey home page Code Monkey logo

payment's Introduction

Payment Build Status npm

A jQuery-free general purpose library for building credit card forms, validating inputs and formatting numbers. Heavily, heavily based on @stripe's jquery.payment library, but without the jQuery.

For example, you can make a input act like a credit card field (with number formatting and length restriction):

Payment.formatCardNumber(document.querySelector('input.cc-num'));

Then, when the payment form is submitted, you can validate the card number on the client-side:

var valid = Payment.fns.validateCardNumber(document.querySelector('input.cc-num').value);

if (!valid) {
  alert('Your card is not valid!');
  return false;
}

You can find a full demo here.

Supported card types are:

  • Visa
  • MasterCard
  • American Express
  • Discover
  • JCB
  • Diners Club
  • Maestro
  • Laser
  • UnionPay
  • Elo
  • Hipercard
  • Troy

API

Payment.formatCardNumber(element[, maxLength])

Formats card numbers:

  • Includes a space between every 4 digits
  • Restricts input to numbers
  • Limits to 16 numbers
  • Supports American Express formatting
  • Adds a class of the card type (e.g. 'visa') to the input
  • If second parameter is specified then card length will be limited to its value (19 digits cards are not in use despite being included in specifications)

Example:

Payment.formatCardNumber(document.querySelector('input.cc-num'));

Payment.formatCardExpiry(element)

Formats card expiry:

  • Includes a / between the month and year
  • Restricts input to numbers
  • Restricts length

Example:

Payment.formatCardExpiry(document.querySelector('input.cc-exp'));

Payment.formatCardCVC(element)

Formats card CVC:

  • Restricts length to 4 numbers
  • Restricts input to numbers

Example:

Payment.formatCardCVC(document.querySelector('input.cc-cvc'));

Payment.restrictNumeric(element)

General numeric input restriction.

Example:

Payment.restrictNumeric(document.querySelector('[data-numeric]'));

Payment.fns.validateCardNumber(number)

Validates a card number:

  • Validates numbers
  • Validates Luhn algorithm
  • Validates length

Example:

Payment.fns.validateCardNumber('4242 4242 4242 4242'); //=> true

Payment.fns.validateCardExpiry(month, year), Payment.fns.validateCardExpiry('month / year')

Validates a card expiry:

  • Validates numbers
  • Validates in the future
  • Supports year shorthand
  • Supports formatted as formatCardExpiry input value

Example:

Payment.fns.validateCardExpiry('05', '20'); //=> true
Payment.fns.validateCardExpiry('05', '2015'); //=> true
Payment.fns.validateCardExpiry('05', '05'); //=> false
Payment.fns.validateCardExpiry('05 / 25'); //=> true
Payment.fns.validateCardExpiry('05 / 2015'); //=> false

Payment.fns.validateCardCVC(cvc, type)

Validates a card CVC:

  • Validates number
  • Validates length to 4

Example:

Payment.fns.validateCardCVC('123'); //=> true
Payment.fns.validateCardCVC('123', 'amex'); //=> true
Payment.fns.validateCardCVC('1234', 'amex'); //=> true
Payment.fns.validateCardCVC('12344'); //=> false

Payment.fns.cardType(number)

Returns a card type. Either:

  • visa
  • mastercard
  • discover
  • amex
  • jcb
  • dinersclub
  • maestro
  • laser
  • unionpay
  • elo
  • hipercard

The function will return null if the card type can't be determined.

Example:

Payment.fns.cardType('4242 4242 4242 4242'); //=> 'visa'

Payment.fns.cardExpiryVal(string) and Payment.cardExpiryVal(el)

Parses a credit card expiry in the form of MM/YYYY, returning an object containing the month and year. Shorthand years, such as 13 are also supported (and converted into the longhand, e.g. 2013).

Payment.fns.cardExpiryVal('03 / 2025'); //=> {month: 3: year: 2025}
Payment.fns.cardExpiryVal('05 / 04'); //=> {month: 5, year: 2004}
Payment.fns.cardExpiryVal(document.querySelector('input.cc-exp')) //=> {month: 4, year: 2020}

This function doesn't perform any validation of the month or year; use Payment.fns.validateCardExpiry(month, year) for that.

Card Type functions

We've provided utility functions to change which card types can be identified by Payment.

Payment.getCardArray()

Returns the array of card types.

Payment.setCardArray(cardTypes)

Overrides the array of card types with a new array.

Payment.addToCardArray(cardType)

Add a new card type to the card array.

Payment.removeFromCardArray(cardName)

Remove a card type from the card array.

Example

Look in ./example/index.html

Building

Run npm run build

Running tests

Run npm run test

Autocomplete recommendations

We recommend you turn autocomplete on for credit card forms, except for the CVC field. You can do this by setting the autocomplete attribute:

<form autocomplete="on">
  <input class="cc-number">
  <input class="cc-cvc" autocomplete="off">
</form>

You should also mark up your fields using the Autofill spec. These are respected by a number of browsers, including Chrome.

<input type="text" class="cc-number" pattern="\d*" autocompletetype="cc-number" placeholder="Card number" required>

Set autocompletetype to cc-number for credit card numbers, cc-exp for credit card expiry and cc-csc for the CVC (security code).

Mobile recommendations

We recommend you set the pattern attribute which will cause the numeric keyboard to be displayed on mobiles:

<input class="cc-number" pattern="\d*">

You may have to turn off HTML5 validation (using the novalidate form attribute) when using this pattern, as it won't match space formatting.

payment's People

Contributors

ahumphreys87 avatar bchelli avatar c0depanda avatar chrissrogers avatar danieljuhl avatar davidmerrique avatar dependabot[bot] avatar desenvolvedorindie avatar gilbarbara avatar gsantiago avatar jeffreyvest avatar jessepollak avatar joelesvensson avatar joshluongo avatar leoetlino avatar lkay avatar melloware avatar piecyk avatar pospi avatar reefdog avatar sertion avatar stevemckenzie avatar trippo avatar willinux-code avatar yoshi3 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

payment's Issues

"jasmine index.spec.js" result => Reference Error: document is not defined

Randomized with seed 07249
Started
..............F...............FF..............................FFFFFFFFFFFFFFFFFFFFFF

Failures:

  1. payment validating card types should validate troy card types
    Message:
    AssertionError [ERR_ASSERTION]: troy
    Stack:
    error properties: Object({ generatedMessage: false, code: 'ERR_ASSERTION', actual: false, expected: true, operator: '==' })
    at
    at UserContext. (D:\GitHub\payment\spec\index.spec.js:114:9)
    at
    at runCallback (timers.js:794:20)
    at tryOnImmediate (timers.js:752:5)
    at processImmediate [as _immediateCallback] (timers.js:729:5)

  2. payment formatCVC should allow only numbers
    Message:
    ReferenceError: document is not defined
    Stack:
    at
    at UserContext. (D:\GitHub\payment\spec\index.spec.js:660:9)
    at
    at runCallback (timers.js:794:20)
    at tryOnImmediate (timers.js:752:5)
    at processImmediate [as _immediateCallback] (timers.js:729:5)

  3. payment formatCVC should restrict to length <= 4
    Message:
    ReferenceError: document is not defined
    Stack:
    at
    at UserContext. (D:\GitHub\payment\spec\index.spec.js:673:9)
    at
    at runCallback (timers.js:794:20)
    at tryOnImmediate (timers.js:752:5)
    at processImmediate [as _immediateCallback] (timers.js:729:5)

  4. payment formatCardNumber should format cc number correctly when transitioning from one length limit to another
    Message:
    ReferenceError: document is not defined
    Stack:
    at
    at UserContext. (D:\GitHub\payment\spec\index.spec.js:507:9)
    at
    at runCallback (timers.js:794:20)
    at tryOnImmediate (timers.js:752:5)
    at processImmediate [as _immediateCallback] (timers.js:729:5)

  5. payment formatCardNumber should set the card type correctly
    Message:
    ReferenceError: document is not defined
    Stack:
    at
    at UserContext. (D:\GitHub\payment\spec\index.spec.js:463:9)
    at
    at runCallback (timers.js:794:20)
    at tryOnImmediate (timers.js:752:5)
    at processImmediate [as _immediateCallback] (timers.js:729:5)

  6. payment formatCardNumber should restrict characters correctly if maxLength exceeds max length for card
    Message:
    ReferenceError: document is not defined
    Stack:
    at
    at UserContext. (D:\GitHub\payment\spec\index.spec.js:407:9)
    at
    at ontimeout (timers.js:482:11)
    at tryOnTimeout (timers.js:317:5)
    at Timer.listOnTimeout (timers.js:277:5)

  7. payment formatCardNumber should remove the space after a number being deleted on a backspace
    Message:
    ReferenceError: document is not defined
    Stack:
    at
    at UserContext. (D:\GitHub\payment\spec\index.spec.js:448:9)
    at
    at runCallback (timers.js:794:20)
    at tryOnImmediate (timers.js:752:5)
    at processImmediate [as _immediateCallback] (timers.js:729:5)

  8. payment formatCardNumber should remove a trailing space before a number on backspace
    Message:
    ReferenceError: document is not defined
    Stack:
    at
    at UserContext. (D:\GitHub\payment\spec\index.spec.js:433:9)
    at
    at runCallback (timers.js:794:20)
    at tryOnImmediate (timers.js:752:5)
    at processImmediate [as _immediateCallback] (timers.js:729:5)

  9. payment formatCardNumber should restrict characters after the length
    Message:
    ReferenceError: document is not defined
    Stack:
    at
    at UserContext. (D:\GitHub\payment\spec\index.spec.js:355:9)
    at
    at runCallback (timers.js:794:20)
    at tryOnImmediate (timers.js:752:5)
    at processImmediate [as _immediateCallback] (timers.js:729:5)

  10. payment formatCardNumber should restrict characters for visa when a maxLength parameter is set despite card length can be 19
    Message:
    ReferenceError: document is not defined
    Stack:
    at
    at UserContext. (D:\GitHub\payment\spec\index.spec.js:394:9)
    at
    at runCallback (timers.js:794:20)
    at tryOnImmediate (timers.js:752:5)
    at processImmediate [as _immediateCallback] (timers.js:729:5)

  11. payment formatCardNumber should restrict characters when a visa card number is greater than 19 characters
    Message:
    ReferenceError: document is not defined
    Stack:
    at
    at UserContext. (D:\GitHub\payment\spec\index.spec.js:381:9)
    at
    at runCallback (timers.js:794:20)
    at tryOnImmediate (timers.js:752:5)
    at processImmediate [as _immediateCallback] (timers.js:729:5)

  12. payment formatCardNumber should format cc number correctly
    Message:
    ReferenceError: document is not defined
    Stack:
    at
    at UserContext. (D:\GitHub\payment\spec\index.spec.js:420:9)
    at
    at runCallback (timers.js:794:20)
    at tryOnImmediate (timers.js:752:5)
    at processImmediate [as _immediateCallback] (timers.js:729:5)

  13. payment formatCardNumber should format correctly on paste
    Message:
    ReferenceError: document is not defined
    Stack:
    at
    at UserContext. (D:\GitHub\payment\spec\index.spec.js:491:9)
    at
    at runCallback (timers.js:794:20)
    at tryOnImmediate (timers.js:752:5)
    at processImmediate [as _immediateCallback] (timers.js:729:5)

  14. payment formatCardNumber should restrict non-number characters
    Message:
    ReferenceError: document is not defined
    Stack:
    at
    at UserContext. (D:\GitHub\payment\spec\index.spec.js:342:9)
    at
    at runCallback (timers.js:794:20)
    at tryOnImmediate (timers.js:752:5)
    at processImmediate [as _immediateCallback] (timers.js:729:5)

  15. payment formatCardNumber should restrict characters when a generic card number is 16 characters
    Message:
    ReferenceError: document is not defined
    Stack:
    at
    at UserContext. (D:\GitHub\payment\spec\index.spec.js:368:9)
    at
    at runCallback (timers.js:794:20)
    at tryOnImmediate (timers.js:752:5)
    at processImmediate [as _immediateCallback] (timers.js:729:5)

  16. payment formatCardExpiry should restrict combined expiry fields to length <= 6 digits
    Message:
    ReferenceError: document is not defined
    Stack:
    at
    at UserContext. (D:\GitHub\payment\spec\index.spec.js:613:9)
    at
    at runCallback (timers.js:794:20)
    at tryOnImmediate (timers.js:752:5)
    at processImmediate [as _immediateCallback] (timers.js:729:5)

  17. payment formatCardExpiry should a number after removing a space and a /
    Message:
    ReferenceError: document is not defined
    Stack:
    at
    at UserContext. (D:\GitHub\payment\spec\index.spec.js:600:9)
    at
    at runCallback (timers.js:794:20)
    at tryOnImmediate (timers.js:752:5)
    at processImmediate [as _immediateCallback] (timers.js:729:5)

  18. payment formatCardExpiry should restrict year expiry fields to length <= 4 digits
    Message:
    ReferenceError: document is not defined
    Stack:
    at
    at UserContext. (D:\GitHub\payment\spec\index.spec.js:642:9)
    at
    at runCallback (timers.js:794:20)
    at tryOnImmediate (timers.js:752:5)
    at processImmediate [as _immediateCallback] (timers.js:729:5)

  19. payment formatCardExpiry should remove spaces trailing space and / after removing a number
    Message:
    ReferenceError: document is not defined
    Stack:
    at
    at UserContext. (D:\GitHub\payment\spec\index.spec.js:587:9)
    at
    at runCallback (timers.js:794:20)
    at tryOnImmediate (timers.js:752:5)
    at processImmediate [as _immediateCallback] (timers.js:729:5)

  20. payment formatCardExpiry should format add a 0 to a number > 1 in the month input correctly
    Message:
    ReferenceError: document is not defined
    Stack:
    at
    at UserContext. (D:\GitHub\payment\spec\index.spec.js:547:9)
    at
    at runCallback (timers.js:794:20)
    at tryOnImmediate (timers.js:752:5)
    at processImmediate [as _immediateCallback] (timers.js:729:5)

  21. payment formatCardExpiry should restrict month expiry fields to length <= 2 digits
    Message:
    ReferenceError: document is not defined
    Stack:
    at
    at UserContext. (D:\GitHub\payment\spec\index.spec.js:626:9)
    at
    at runCallback (timers.js:794:20)
    at tryOnImmediate (timers.js:752:5)
    at processImmediate [as _immediateCallback] (timers.js:729:5)

  22. payment formatCardExpiry should format forward slash shorthand correctly
    Message:
    ReferenceError: document is not defined
    Stack:
    at
    at UserContext. (D:\GitHub\payment\spec\index.spec.js:561:9)
    at
    at runCallback (timers.js:794:20)
    at tryOnImmediate (timers.js:752:5)
    at processImmediate [as _immediateCallback] (timers.js:729:5)

  23. payment formatCardExpiry should only allow numbers
    Message:
    ReferenceError: document is not defined
    Stack:
    at
    at UserContext. (D:\GitHub\payment\spec\index.spec.js:574:9)
    at
    at runCallback (timers.js:794:20)
    at tryOnImmediate (timers.js:752:5)
    at processImmediate [as _immediateCallback] (timers.js:729:5)

  24. payment formatCardExpiry should add a slash after two numbers
    Message:
    ReferenceError: document is not defined
    Stack:
    at
    at UserContext. (D:\GitHub\payment\spec\index.spec.js:522:9)
    at
    at runCallback (timers.js:794:20)
    at tryOnImmediate (timers.js:752:5)
    at processImmediate [as _immediateCallback] (timers.js:729:5)

  25. payment formatCardExpiry should format add a 0 and slash to a number > 1 correctly
    Message:
    ReferenceError: document is not defined
    Stack:
    at
    at UserContext. (D:\GitHub\payment\spec\index.spec.js:535:9)
    at
    at ontimeout (timers.js:482:11)
    at tryOnTimeout (timers.js:317:5)
    at Timer.listOnTimeout (timers.js:277:5)

84 specs, 25 failures
Finished in 0.437 seconds
Randomized with seed 07249 (jasmine --random=true --seed=07249)

Expose formatCardCVC and formatCardExpiry under Payment.fns

Hi - great library, thanks for your work on it.

I'm trying to integrate this library with a React.js payment form. This stops me from using and direct event handlers on the input fields.

I've had success with using the Payment.fns.formatCardNumber function to help me format my user input as part of the react data flow but unfortunately the related functions for expiry and cvc are not exposed in their non-event-handler form as the card number function is.

Would it be possible to expose these so I can use them as stand alone string formatters?

Thanks!

Old elo's pattern

Hey there, didn't find any guideline to open a issue in this repo, neither to open a pull request, but here i am haha!

So, my issue is with Elo's credit card number validation, some new numbers aren't being detected.

The fix is simple, just update the actual regex to the new one, based on this gist comment https://gist.github.com/erikhenrique/5931368#gistcomment-1683630

index bbc9246..a384543 100644
--- a/src/index.coffee
+++ b/src/index.coffee
@@ -93,7 +93,7 @@ cards = [
   }
   {
       type: 'elo'
-      pattern: /^(4011(78|79)|43(1274|8935)|45(1416|7393|763(1|2))|50(4175|6699|67[0-7][0-9]|9000)|627780|63(6297|6368)|650(03([^4])|04([0-9])|05(0|1)|4(0[5-9]|3[0-9]|8[5-9]|9[0-9])|5([0-2][0-9]|3[0-8])|9([2-6][0-9]|7[0-8])|541|700|720|901)|651652|655000|655021)/,
+      pattern: /^401178|^401179|^431274|^438935|^451416|^457393|^457631|^457632|^504175|^627780|^636297|^636369|^(506699|5067[0-6]\d|50677[0-8])|^(50900\d|5090[1-9]\d|509[1-9]\d{2})|^65003[1-3]|^(65003[5-9]|65004\d|65005[0-1])|^(65040[5-9]|6504[1-3]\d)|^(65048[5-9]|65049\d|6505[0-2]\d|65053[0-8])|^(65054[1-9]|6505[5-8]\d|65059[0-8])|^(65070\d|65071[0-8])|^65072[0-7]|^(65090[1-9]|65091\d|650920)|^(65165[2-9]|6516[6-7]\d)|^(65500\d|65501\d)|^(65502[1-9]|6550[3-4]\d|65505[0-8])/,
       format: defaultFormat
       length: [16]
       cvcLength: [3]

Thanks!

The following (valid) credit card number is not accepted

For some reason the following credit card number is not accepted:
5043342567607506

A quick check on the net shows that the Luhn algorithm accepts this number as a valid credit card number. We also don't have any issues using this card number on our sister website (which uses the JQuery.payment library) so there might be something wrong.

The entire card details:

Mastercard test card + OTP
Card Number: 5043342567607506
Expiry details: 09/21
CVV: 563
PIN: 1111
OTP: 123456

Below is A GIF of me trying to validate this card number:

issue_card_validation

Support MasterCard series 2 bins

Mastercard is introducing a new range of card numbers with IINs ranging from 22210000 to 27209999, effective on October 14th.

Relevant links: [1], [2]

hasTextSelected bug in IE8

[https://github.com/jessepollak/payment/blob/master/lib/payment.js#L360]
CoffeeScript generated code asserts that document.selection.createRange is a function:

hasTextSelected = function($target) {
    var _ref;
    if (($target.prop('selectionStart') != null) && $target.prop('selectionStart') !== $target.prop('selectionEnd')) {
      return true;
    }
    if (typeof document !== "undefined" && document !== null ? (_ref = document.selection) != null ? typeof _ref.createRange === "function" ? _ref.createRange().text : void 0 : void 0 : void 0) {
      return true;
    }
    return false;
  };

But actually in IE8:

>>typeof document.selection.createRange
"object"

so it always return false in IE8

Including via NPM complains that its pre-built

Hi,
I am including the payment module in a node application, and building with webpack. I see the following warning when building:

WARNING in .//payment/lib/payment.js
Critical dependencies:
1:459-466 This seem to be a pre-built javascript file. Even while this is possible, it's not recommended. Try to require to orginal source to get better results.
@ ./
/payment/lib/payment.js 1:459-466

Can't select and overwrite CVC when it's full

Steps to reproduce:

  1. Enter four digits into the CVC field
  2. Select the digits
  3. Attempt to type more digits to delete the selected digits and replace with new ones

Expected: Same behavior as the number/expiry fields (and as normal text selection in inputs)

Actual: Typing blocked as if I was trying to add more than four digits

Notes: I can see that restrictCardNumber()/restrictExpiry() make use of hasTextSelected() to allow this. Any reason restrictCVC() doesn't similarly allow it?

I tried to fork and make this change myself, but I don't have experience with gulp and wasn't able to build the production files. (Tried roughly following the directions on Card development section.) I actually need this change for Card, but figured I'd drop the issue upstream where it mattered.

Love the library, btw. Thank you.

DOM-free version?

Hi,

This library is not coupled to JQuery but it's coupled to DOM.

I'd like to use it in ReactNative project but it seems not possible as method inputs are using DOM elements. I guess it could make sense to make a DOM-free version? Some functions like the formatting ones are not exposed with a DOM-free API.

keypress event is ignored on android (mobile)

On android devices keypress events are not being triggered.
Input is not being validated/formatted as a result. it works fine on desktop and iOS.

I used two android(v6 and v4.4) devices to test this using chrome/stock browser.

can be reproduced here: http://jessepollak.github.io/payment/example/

Example above demonstrates that card number is not being validated because
https://github.com/jessepollak/payment/blob/master/lib/payment.js#L787 is not being triggered

Payment.formatCardNumber is allowing 19 digits

I want to limit the credit card digits to 16, but still it is allowing 19 digits.
Code:
Payment.formatCardNumber(document.querySelector('input.cc-number'), 16);
What shall I do to restrict it to 16.

Overrides global Payment

This is setting a global Payment. Can we make it not do this? Is there an option to control this?

"Error: Cannot find module 'coffeeify' from 'card-react/node_modules/payment'"

Hi @jessepollak,
After I've updated card-react to get payment v0.0.10, I get this error when i try to build it:
"Error: Cannot find module 'coffeeify' from 'card-react/node_modules/payment'"
and i've noticed you added coffeeify browserify transform to package.json.
So i think 'coffeeify should be added to 'dependencies' section in package.json.
I've added it in card-react's package.json and it works but i think it should be in 'payment'.

Visa cards issue

When entering visa cards, input takes more than 16 digits. Mastercard works fine.

Marker jumping to end when editing card number

Description

When you delete a character in the card number and it's not from the end (latest digit) then the marker jumps to the end of the card number.

Steps to reproduce

  1. Enter a card number
  2. Delete the middle most number in the card number
  3. The marker jumps to the end

Expected behaviour

That the marker does not jump to the end, and actually stays where it was placed.

Edit: This seems to only happen when bundled with an Angular 4 application
Edit: It seems like it's the compiling that goes wrong. We compile it ourselves, but when we do, this line gets added on line 636:
QJ.on(el, 'input', reFormatCardNumber);
This seems to be the culprit. It looks like it could be an issue with the NPM version. Can you tell me what version of NPM you build this on? @jessepollak

Does not build under webpack

Modules which require(payment) as a dependency cause production webpack builds to fail. It seems like the fact that all files are bundled together is an issue; suspect the fix is to setup a build process that compiles each coffeescript file into a separate javascript file, rather than bundling them all together.

The error webpack outputs is:

WARNING in ./~/card-react/~/payment/lib/payment.js
Critical dependencies:
1:459-466 This seems to be a pre-built javascript file. Though this is possible, it's not recommended. Try to require the original source to get better results.
 @ ./~/card-react/~/payment/lib/payment.js 1:459-466

Though it presents as a warning and will pass in some development configurations, it will fail in a production build command.

Android spacing for credit card does not seem to work

Using Samsung S7 edge for any browser. The correct spacing on the input works for Payment.formatCardNumber(document.querySelector('input.card-number'));
It works for everything else on Desktop and iPhone - I've tried - IE, Firefox, Safari, Opera. <input type="text" id="payment-1" class="card-number form-control" id="card-number" placeholder="Card Number">

Troy Credit Card Support

Hi, can you add support for Troy credit cards ?

Troy credit card patterns : /^(?:9792|65\d{2}|36|2205)\d{12}$ /

Issue with formatCardNumber - erased characters reappearing on validate

Using 2.2.1

screen shot 2017-05-09 at 11 59 22 am

^ It appears like the field is allowing 19 characters + 3 spaces. When a user accidentally goes over 16 characters like in the photo 4242 4242 4242 4242 333 and then goes to erase the extra characters => 4242 4242 4242 4242, and clicks Submit to validate the card, a previously erased extra character appears in the input field => 4242 4242 4242 4242 3 and the card returns invalid.

The input masking is implemented in React, but this probably shouldn't matter.

screen shot 2017-05-09 at 12 30 54 pm

Issue with multiple forms on the page

Hi,

I can't get the form selector to work properly, if I try to select it by ID or by class, I don't get anything, if I let the $('form') selector, it finds its container, adds the image, but can't find the fields (although they are here).

I think this is an issue with the form selector

Card can't find a numberInput in your form.
Card can't find a expiryInput in your form.
Card can't find a cvcInput in your form.
Card can't find a nameInput in your form.

Alex

Maximum call stach execution

I have simple form that validates CVC and card number and I am checking on click:
console.log(Payment.formatCardCVC(CVCIn.val()));return;, For the first tie when I press the button it works, but if I change the input and press again, I am getting this error:

card-validation.js?ver=1:749 Uncaught RangeError: Maximum call stack size exceeded
at Function.QJ.on (card-validation.js?ver=1:749)

Build instructions are wrong

Hey,

The build instructions on the README are wrong :) It seems the project now uses direct scripts using npm build, npm run test etc.. Instead of the old gulp system.

It would be great to update the README !

React/Redux formatting issue

Referencing #53

When using React/Redux there is an issue when trying to format a card number and expiration date.
For the card, I can't type beyond four digits because it says it's not a valid number and for the date I can't type beyond two digits because I get the same error.

restrictNumeric blocks pasting with Ctrl+V

restrictNumeric() correctly checks for e.metaKey || e.ctrlKey, but these are always undefined because QJ.normalizeEvent() doesn't copy them from the original event.

Relevant links to the code:

#57 is probably the same issue, since formatCardNumber() uses restrictNumeric().

Months from 13 to 19 are formatted wrong

Hello!

As the title: if I insert numbers from 13 to 19 they are considered valid months. IMHO it should work like when you write 2{d} and it gets formatted as "02/{d}", writing 13 should become "01/3".

Thanks for this library โœŒ๏ธ

BUG: Mastercard pattern property defined twice

MasterCard pattern property is defined twice in constructor and it's not allowed in Javascript strict mode, resulting in error when building, for example, your card with something like Rollup and executing with 'strict mode'

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.