Comparing version 2.2.1 to 2.3.0
{ | ||
"name": "payment", | ||
"version": "2.2.1", | ||
"version": "2.3.0", | ||
"main": "dist/payment.js" | ||
} |
@@ -46,3 +46,3 @@ var payment = | ||
/* 0 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -214,38 +214,43 @@ /* WEBPACK VAR INJECTION */(function(global) {var Payment, QJ, cardFromNumber, cardFromType, cards, defaultFormat, formatBackCardNumber, formatBackExpiry, formatCardNumber, formatExpiry, formatForwardExpiry, formatForwardSlash, formatMonthExpiry, hasTextSelected, luhnCheck, reFormatCardNumber, restrictCVC, restrictCardNumber, restrictCombinedExpiry, restrictExpiry, restrictMonthExpiry, restrictNumeric, restrictYearExpiry, setCardType, | ||
formatCardNumber = function(e) { | ||
var card, digit, i, j, len, length, re, target, upperLength, upperLengths, value; | ||
digit = String.fromCharCode(e.which); | ||
if (!/^\d+$/.test(digit)) { | ||
return; | ||
} | ||
target = e.target; | ||
value = QJ.val(target); | ||
card = cardFromNumber(value + digit); | ||
length = (value.replace(/\D/g, '') + digit).length; | ||
upperLengths = [16]; | ||
if (card) { | ||
upperLengths = card.length; | ||
} | ||
for (i = j = 0, len = upperLengths.length; j < len; i = ++j) { | ||
upperLength = upperLengths[i]; | ||
if (length >= upperLength && upperLengths[i + 1]) { | ||
continue; | ||
formatCardNumber = function(maxLength) { | ||
return function(e) { | ||
var card, digit, i, j, len, length, re, target, upperLength, upperLengths, value; | ||
digit = String.fromCharCode(e.which); | ||
if (!/^\d+$/.test(digit)) { | ||
return; | ||
} | ||
if (length >= upperLength) { | ||
target = e.target; | ||
value = QJ.val(target); | ||
card = cardFromNumber(value + digit); | ||
length = (value.replace(/\D/g, '') + digit).length; | ||
upperLengths = [16]; | ||
if (card) { | ||
upperLengths = card.length; | ||
} | ||
if (maxLength) { | ||
upperLengths = [Math.min(maxLength, upperLengths.slice(0).pop())]; | ||
} | ||
for (i = j = 0, len = upperLengths.length; j < len; i = ++j) { | ||
upperLength = upperLengths[i]; | ||
if (length >= upperLength && upperLengths[i + 1]) { | ||
continue; | ||
} | ||
if (length >= upperLength) { | ||
return; | ||
} | ||
} | ||
if (hasTextSelected(target)) { | ||
return; | ||
} | ||
} | ||
if (hasTextSelected(target)) { | ||
return; | ||
} | ||
if (card && card.type === 'amex') { | ||
re = /^(\d{4}|\d{4}\s\d{6})$/; | ||
} else { | ||
re = /(?:^|\s)(\d{4})$/; | ||
} | ||
if (re.test(value)) { | ||
e.preventDefault(); | ||
QJ.val(target, value + ' ' + digit); | ||
return QJ.trigger(target, 'change'); | ||
} | ||
if (card && card.type === 'amex') { | ||
re = /^(\d{4}|\d{4}\s\d{6})$/; | ||
} else { | ||
re = /(?:^|\s)(\d{4})$/; | ||
} | ||
if (re.test(value)) { | ||
e.preventDefault(); | ||
QJ.val(target, value + ' ' + digit); | ||
return QJ.trigger(target, 'change'); | ||
} | ||
}; | ||
}; | ||
@@ -387,23 +392,26 @@ | ||
restrictCardNumber = function(e) { | ||
var card, digit, target, value; | ||
target = e.target; | ||
digit = String.fromCharCode(e.which); | ||
if (!/^\d+$/.test(digit)) { | ||
return; | ||
} | ||
if (hasTextSelected(target)) { | ||
return; | ||
} | ||
value = (QJ.val(target) + digit).replace(/\D/g, ''); | ||
card = cardFromNumber(value); | ||
if (card) { | ||
if (!(value.length <= card.length[card.length.length - 1])) { | ||
return e.preventDefault(); | ||
restrictCardNumber = function(maxLength) { | ||
return function(e) { | ||
var card, digit, length, target, value; | ||
target = e.target; | ||
digit = String.fromCharCode(e.which); | ||
if (!/^\d+$/.test(digit)) { | ||
return; | ||
} | ||
} else { | ||
if (!(value.length <= 16)) { | ||
if (hasTextSelected(target)) { | ||
return; | ||
} | ||
value = (QJ.val(target) + digit).replace(/\D/g, ''); | ||
card = cardFromNumber(value); | ||
length = 16; | ||
if (card) { | ||
length = card.length[card.length.length - 1]; | ||
} | ||
if (maxLength) { | ||
length = Math.min(length, maxLength); | ||
} | ||
if (!(value.length <= length)) { | ||
return e.preventDefault(); | ||
} | ||
} | ||
}; | ||
}; | ||
@@ -576,6 +584,10 @@ | ||
groups = card.format.exec(num); | ||
if (groups != null) { | ||
groups.shift(); | ||
if (groups == null) { | ||
return; | ||
} | ||
return groups != null ? groups.join(' ') : void 0; | ||
groups.shift(); | ||
groups = groups.filter(function(n) { | ||
return n; | ||
}); | ||
return groups.join(' '); | ||
} | ||
@@ -621,6 +633,6 @@ } | ||
Payment.formatCardNumber = function(el) { | ||
Payment.formatCardNumber = function(el, maxLength) { | ||
Payment.restrictNumeric(el); | ||
QJ.on(el, 'keypress', restrictCardNumber); | ||
QJ.on(el, 'keypress', formatCardNumber); | ||
QJ.on(el, 'keypress', restrictCardNumber(maxLength)); | ||
QJ.on(el, 'keypress', formatCardNumber(maxLength)); | ||
QJ.on(el, 'keydown', formatBackCardNumber); | ||
@@ -666,5 +678,5 @@ QJ.on(el, 'keyup blur', setCardType); | ||
/***/ }, | ||
/***/ }), | ||
/* 1 */ | ||
/***/ function(module, exports) { | ||
/***/ (function(module, exports) { | ||
@@ -906,3 +918,3 @@ // Generated by CoffeeScript 1.10.0 | ||
/***/ } | ||
/***/ }) | ||
/******/ ]); |
138
lib/index.js
@@ -26,2 +26,9 @@ // Generated by CoffeeScript 1.10.0 | ||
}, { | ||
type: 'hipercard', | ||
pattern: /^(384100|384140|384160|606282|637095|637568|60(?!11))/, | ||
format: defaultFormat, | ||
length: [14, 15, 16, 17, 18, 19], | ||
cvcLength: [3], | ||
luhn: true | ||
}, { | ||
type: 'dinersclub', | ||
@@ -84,3 +91,3 @@ pattern: /^(36|38|30[0-5])/, | ||
type: 'elo', | ||
pattern: /^(4011|438935|45(1416|76|7393)|50(4175|6699|67|90[4-7])|63(6297|6368))/, | ||
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)/, | ||
format: defaultFormat, | ||
@@ -170,38 +177,45 @@ length: [16], | ||
formatCardNumber = function(e) { | ||
var card, digit, i, j, len, length, re, target, upperLength, upperLengths, value; | ||
digit = String.fromCharCode(e.which); | ||
if (!/^\d+$/.test(digit)) { | ||
return; | ||
} | ||
target = e.target; | ||
value = QJ.val(target); | ||
card = cardFromNumber(value + digit); | ||
length = (value.replace(/\D/g, '') + digit).length; | ||
upperLengths = [16]; | ||
if (card) { | ||
upperLengths = card.length; | ||
} | ||
for (i = j = 0, len = upperLengths.length; j < len; i = ++j) { | ||
upperLength = upperLengths[i]; | ||
if (length >= upperLength && upperLengths[i + 1]) { | ||
continue; | ||
formatCardNumber = function(maxLength) { | ||
return function(e) { | ||
var card, digit, i, j, len, length, re, target, upperLength, upperLengths, value; | ||
digit = String.fromCharCode(e.which); | ||
if (!/^\d+$/.test(digit)) { | ||
return; | ||
} | ||
if (length >= upperLength) { | ||
target = e.target; | ||
value = QJ.val(target); | ||
card = cardFromNumber(value + digit); | ||
length = (value.replace(/\D/g, '') + digit).length; | ||
upperLengths = [16]; | ||
if (card) { | ||
upperLengths = card.length; | ||
} | ||
if (maxLength) { | ||
upperLengths = upperLengths.filter(function(x) { | ||
return x <= maxLength; | ||
}); | ||
} | ||
for (i = j = 0, len = upperLengths.length; j < len; i = ++j) { | ||
upperLength = upperLengths[i]; | ||
if (length >= upperLength && upperLengths[i + 1]) { | ||
continue; | ||
} | ||
if (length >= upperLength) { | ||
return; | ||
} | ||
} | ||
if (hasTextSelected(target)) { | ||
return; | ||
} | ||
} | ||
if (hasTextSelected(target)) { | ||
return; | ||
} | ||
if (card && card.type === 'amex') { | ||
re = /^(\d{4}|\d{4}\s\d{6})$/; | ||
} else { | ||
re = /(?:^|\s)(\d{4})$/; | ||
} | ||
if (re.test(value)) { | ||
e.preventDefault(); | ||
QJ.val(target, value + ' ' + digit); | ||
return QJ.trigger(target, 'change'); | ||
} | ||
if (card && card.type === 'amex') { | ||
re = /^(\d{4}|\d{4}\s\d{6})$/; | ||
} else { | ||
re = /(?:^|\s)(\d{4})$/; | ||
} | ||
if (re.test(value)) { | ||
e.preventDefault(); | ||
QJ.val(target, value + ' ' + digit); | ||
return QJ.trigger(target, 'change'); | ||
} | ||
}; | ||
}; | ||
@@ -343,23 +357,26 @@ | ||
restrictCardNumber = function(e) { | ||
var card, digit, target, value; | ||
target = e.target; | ||
digit = String.fromCharCode(e.which); | ||
if (!/^\d+$/.test(digit)) { | ||
return; | ||
} | ||
if (hasTextSelected(target)) { | ||
return; | ||
} | ||
value = (QJ.val(target) + digit).replace(/\D/g, ''); | ||
card = cardFromNumber(value); | ||
if (card) { | ||
if (!(value.length <= card.length[card.length.length - 1])) { | ||
return e.preventDefault(); | ||
restrictCardNumber = function(maxLength) { | ||
return function(e) { | ||
var card, digit, length, target, value; | ||
target = e.target; | ||
digit = String.fromCharCode(e.which); | ||
if (!/^\d+$/.test(digit)) { | ||
return; | ||
} | ||
} else { | ||
if (!(value.length <= 16)) { | ||
if (hasTextSelected(target)) { | ||
return; | ||
} | ||
value = (QJ.val(target) + digit).replace(/\D/g, ''); | ||
card = cardFromNumber(value); | ||
length = 16; | ||
if (card) { | ||
length = card.length[card.length.length - 1]; | ||
} | ||
if (maxLength) { | ||
length = Math.min(length, maxLength); | ||
} | ||
if (!(value.length <= length)) { | ||
return e.preventDefault(); | ||
} | ||
} | ||
}; | ||
}; | ||
@@ -532,6 +549,10 @@ | ||
groups = card.format.exec(num); | ||
if (groups != null) { | ||
groups.shift(); | ||
if (groups == null) { | ||
return; | ||
} | ||
return groups != null ? groups.join(' ') : void 0; | ||
groups.shift(); | ||
groups = groups.filter(function(n) { | ||
return n; | ||
}); | ||
return groups.join(' '); | ||
} | ||
@@ -577,9 +598,10 @@ } | ||
Payment.formatCardNumber = function(el) { | ||
Payment.formatCardNumber = function(el, maxLength) { | ||
Payment.restrictNumeric(el); | ||
QJ.on(el, 'keypress', restrictCardNumber); | ||
QJ.on(el, 'keypress', formatCardNumber); | ||
QJ.on(el, 'keypress', restrictCardNumber(maxLength)); | ||
QJ.on(el, 'keypress', formatCardNumber(maxLength)); | ||
QJ.on(el, 'keydown', formatBackCardNumber); | ||
QJ.on(el, 'keyup blur', setCardType); | ||
QJ.on(el, 'paste', reFormatCardNumber); | ||
QJ.on(el, 'input', reFormatCardNumber); | ||
return el; | ||
@@ -586,0 +608,0 @@ }; |
{ | ||
"name": "payment", | ||
"version": "2.2.1", | ||
"version": "2.3.0", | ||
"description": "A general purpose library for building credit card forms, validating inputs and formatting numbers. Base on jquery.payment by @stripe, but without the jQuery.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -36,6 +36,7 @@ # Payment [![Build Status](https://travis-ci.org/jessepollak/payment.svg?branch=master)](https://travis-ci.org/jessepollak/payment) | ||
* Elo | ||
* Hipercard | ||
## API | ||
### Payment.formatCardNumber | ||
### Payment.formatCardNumber(element[, maxLength]) | ||
Formats card numbers: | ||
@@ -48,2 +49,3 @@ | ||
* 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) | ||
@@ -56,3 +58,3 @@ Example: | ||
### Payment.formatCardExpiry | ||
### Payment.formatCardExpiry(element) | ||
@@ -71,3 +73,3 @@ Formats card expiry: | ||
### Payment.formatCardCVC | ||
### Payment.formatCardCVC(element) | ||
Formats card CVC: | ||
@@ -84,3 +86,3 @@ | ||
### Payment.restrictNumeric | ||
### Payment.restrictNumeric(element) | ||
@@ -158,2 +160,3 @@ General numeric input restriction. | ||
* `elo` | ||
* `hipercard` | ||
@@ -160,0 +163,0 @@ The function will return `null` if the card type can't be determined. |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
54454
1508
237