Security News
NVD Backlog Tops 20,000 CVEs Awaiting Analysis as NIST Prepares System Updates
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
A general purpose library for building credit card forms, validating inputs and formatting numbers. Base on jquery.payment by @stripe, but without the jQuery.
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:
Formats card numbers:
Example:
Payment.formatCardNumber(document.querySelector('input.cc-num'));
Formats card expiry:
/
between the month and yearExample:
Payment.formatCardExpiry(document.querySelector('input.cc-exp'));
Formats card CVC:
Example:
Payment.formatCardCVC(document.querySelector('input.cc-cvc'));
General numeric input restriction.
Example:
Payment.restrictNumeric(document.querySelector('[data-numeric]'));
Validates a card number:
Example:
Payment.fns.validateCardNumber('4242 4242 4242 4242'); //=> true
Validates a card expiry:
Example:
Payment.fns.validateCardExpiry('05', '20'); //=> true
Payment.fns.validateCardExpiry('05', '2015'); //=> true
Payment.fns.validateCardExpiry('05', '05'); //=> false
Validates a card CVC:
Example:
Payment.fns.validateCardCVC('123'); //=> true
Payment.fns.validateCardCVC('123', 'amex'); //=> true
Payment.fns.validateCardCVC('1234', 'amex'); //=> true
Payment.fns.validateCardCVC('12344'); //=> false
Returns a card type. Either:
visa
mastercard
discover
amex
jcb
dinersclub
maestro
laser
unionpay
elo
The function will return null
if the card type can't be determined.
Example:
Payment.fns.cardType('4242 4242 4242 4242'); //=> 'visa'
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.
We've provided utility functions to change which card types can be identified by Payment.
Returns the array of card types.
Overrides the array of card types with a new array.
Add a new card type to the card array.
Remove a card type from the card array.
Look in ./example/index.html
Run gulp build
Run gulp test
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).
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.
FAQs
A general purpose library for building credit card forms, validating inputs and formatting numbers. Base on jquery.payment by @stripe, but without the jQuery.
The npm package payment receives a total of 65,146 weekly downloads. As such, payment popularity was classified as popular.
We found that payment demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.