Skip to content

Commit cfdb6c3

Browse files
committed
Allowed credit card numbers to contain spaces as well as dashes (spaces are commonly input by users). Resolves (jquery-validation#47, jquery-validation#39, jquery-validation#32)
* Changed code to allow spaces * Amended comment * Added Qunit tests.
1 parent 27a78df commit cfdb6c3

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

jquery.validate.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,8 +1061,8 @@ $.extend($.validator, {
10611061
creditcard: function(value, element) {
10621062
if ( this.optional(element) )
10631063
return "dependency-mismatch";
1064-
// accept only digits and dashes
1065-
if (/[^0-9-]+/.test(value))
1064+
// accept only spaces, digits and dashes
1065+
if (/[^0-9 -]+/.test(value))
10661066
return false;
10671067
var nCheck = 0,
10681068
nDigit = 0,

test/methods.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ test("equalTo", function() {
340340
test("creditcard", function() {
341341
var method = methodTest("creditcard");
342342
ok( method( "446-667-651" ), "Valid creditcard number" );
343+
ok( method( "446 667 651" ), "Valid creditcard number" );
343344
ok( !method( "asdf" ), "Invalid creditcard number" );
344345
});
345346

0 commit comments

Comments
 (0)