Skip to content

Commit 4334577

Browse files
committed
cvv validation now supports amex victorjonsson#197
1 parent 0cd6b32 commit 4334577

File tree

11 files changed

+63
-24
lines changed

11 files changed

+63
-24
lines changed

form-validator/date.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* @website http://formvalidator.net/#location-validators
1212
* @license Dual licensed under the MIT or GPL Version 2 licenses
13-
* @version 2.2.beta.13
13+
* @version 2.2.beta.15
1414
*/
1515
(function($) {
1616

form-validator/file.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* @website http://formvalidator.net/
1212
* @license Dual licensed under the MIT or GPL Version 2 licenses
13-
* @version 2.2.beta.13
13+
* @version 2.2.beta.15
1414
*/
1515
(function($, window) {
1616

form-validator/html5.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*
1818
* @website http://formvalidator.net/
1919
* @license Dual licensed under the MIT or GPL Version 2 licenses
20-
* @version 2.2.beta.13
20+
* @version 2.2.beta.15
2121
*/
2222
(function($, window) {
2323

form-validator/jquery.form-validator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* @website http://formvalidator.net/
77
* @license Dual licensed under the MIT or GPL Version 2 licenses
8-
* @version 2.2.beta.13
8+
* @version 2.2.beta.15
99
*/
1010
(function($) {
1111

form-validator/jquery.form-validator.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

form-validator/location.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* @website http://formvalidator.net/#location-validators
1212
* @license Dual licensed under the MIT or GPL Version 2 licenses
13-
* @version 2.2.beta.13
13+
* @version 2.2.beta.15
1414
*/
1515
(function($) {
1616

form-validator/qunit.html

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@
253253

254254
var links = [
255255
{val:'012', isValid:true},
256+
{val:'0124', isValid:false},
256257
{val:'000', isValid:true},
257258
{val:'01', isValid:false},
258259
{val:'a12', isValid:false}
@@ -261,6 +262,28 @@
261262
$.each(links, function(i, obj) {
262263
runTest(obj, 'cvv');
263264
});
265+
266+
// check with amex only
267+
var $cCard = input('', {'allowing':'amex', '':'creditcard'}),
268+
$cvv = input('1234', 'cvv'),
269+
result;
270+
271+
// let the validator know which type of card we're validating
272+
$.formUtils.validateInput($cCard, $.formUtils.LANG, $.formUtils.defaultConfig(), $form)
273+
274+
result = $.formUtils.validateInput($cvv, $.formUtils.LANG, $.formUtils.defaultConfig(), $form);
275+
equal(
276+
true,
277+
result
278+
);
279+
280+
$cvv.val('123');
281+
result = $.formUtils.validateInput($cvv, $.formUtils.LANG, $.formUtils.defaultConfig(), $form);
282+
equal(
283+
'string',
284+
typeof result
285+
);
286+
264287
});
265288

266289

form-validator/security.dev.js

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* - cvv
1414
*
1515
* @website http://formvalidator.net/#security-validators
16-
* @version 2.2.beta.13
16+
* @version 2.2.beta.15
1717
*/
1818
(function($, window) {
1919

@@ -55,31 +55,37 @@
5555
errorMessageKey: 'notConfirmed'
5656
});
5757

58+
var creditCards = {
59+
'amex' : [15,15],
60+
'diners_club' : [14,14],
61+
'cjb' : [16,16],
62+
'laser' : [16,19],
63+
'visa' : [16,16],
64+
'mastercard' : [16,16],
65+
'maestro' : [12,19],
66+
'discover' : [16,16]
67+
},
68+
checkOnlyAmex = false,
69+
allowsAmex = false;
70+
5871
/*
5972
* Credit card
6073
*/
6174
$.formUtils.addValidator({
6275
name : 'creditcard',
6376
validatorFunction : function(value, $el, config, language, $form) {
64-
var cards = {
65-
'amex' : [15,15],
66-
'diners_club' : [14,14],
67-
'cjb' : [16,16],
68-
'laser' : [16,19],
69-
'visa' : [16,16],
70-
'mastercard' : [16,16],
71-
'maestro' : [12,19],
72-
'discover' : [16,16]
73-
},
74-
allowing = $.split( $el.valAttr('allowing') || '' );
77+
var allowing = $.split( $el.valAttr('allowing') || '' );
7578

79+
// Setup for cvv validation
80+
allowsAmex = $.inArray('amex', allowing) > -1;
81+
checkOnlyAmex = allowsAmex && allowing.length == 1;
7682

7783
// Correct length
7884
if( allowing.length > 0 ) {
7985
var hasValidLength = false;
8086
$.each(allowing, function(i, cardName) {
81-
if( cardName in cards) {
82-
if( value.length >= cards[cardName][0] && value.length <= cards[cardName][1]) {
87+
if( cardName in creditCards) {
88+
if( value.length >= creditCards[cardName][0] && value.length <= creditCards[cardName][1]) {
8389
hasValidLength = true;
8490
return false;
8591
}
@@ -126,7 +132,17 @@
126132
$.formUtils.addValidator({
127133
name : 'cvv',
128134
validatorFunction : function(val) {
129-
return val.replace(/[0-9]/g, '') === '' && (val + '').length == 3;
135+
if( val.replace(/[0-9]/g, '') === '' ) {
136+
val = val + '';
137+
if( checkOnlyAmex ) {
138+
return val.length == 4;
139+
} else if( allowsAmex ) {
140+
return val.length == 3 || val.length == 4;
141+
} else {
142+
return val.length == 3;
143+
}
144+
}
145+
return false;
130146
},
131147
errorMessage : '',
132148
errorMessageKey: 'badCVV'

form-validator/security.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

form-validator/sweden.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
* @website http://formvalidator.net/#swedish-validators
1515
* @license Dual licensed under the MIT or GPL Version 2 licenses
16-
* @version 2.2.beta.13
16+
* @version 2.2.beta.15
1717
*/
1818
(function($, window) {
1919

form-validator/uk.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
* @website http://formvalidator.net/#uk-validators
1111
* @license Dual licensed under the MIT or GPL Version 2 licenses
12-
* @version 2.2.beta.13
12+
* @version 2.2.beta.15
1313
*/
1414
$.formUtils.addValidator({
1515
name : 'ukvatnumber',

0 commit comments

Comments
 (0)