stripe-archive / jquery.payment

[DEPRECATED] A general purpose library for building credit card forms, validating inputs and formatting numbers.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Spaces aren't inserted correctly when formatting a card number input

courthead opened this issue · comments

STR:

  • Go to the demo.
  • In the card number field, type 12345.
  • Expected: The input now reads 1234 5.
  • Actual: The input now reads 12345.

I think this commit is the culprit: 3dc241e

After this commit, all non-digits are stripped from the number inserted after each keystroke.

12345 doesn't match any known credit card formats, so jquery.payment doesn't know how to format it. Try 4242 4242 4242 4242 for a valid fake Visa, for example. You can see some additional fake cards here: https://stripe.com/docs/testing

Ah, I was thinking that even if the user makes a mistake (resulting in the number being invalid), it'd be nice to still format the numbers in some common way, like groups of four separated by spaces (e.g. 1234 5678 9012 3456).

Actually, @courthead suggestion (4-digit groups instead of ungrouped by default) makes sense. It would be great if this behavior could be configurable.

@jenanwise: Would you guys be interested in adding something in that line?