Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Add missing `var` #1

Merged
merged 2 commits into from over 2 years ago

2 participants

Mathias Bynens Thomas Fuchs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.

Showing 2 changed files with 6 additions and 6 deletions. Show diff stats Hide diff stats

  1. +5 5 creditcard.js
  2. +1 1  creditcard.min.js
10 creditcard.js
... ... @@ -1,6 +1,6 @@
1 1 // Copyright (c) 2008 Thomas Fuchs
2 2 // http://script.aculo.us/thomas
3   -//
  3 +//
4 4 // Permission is hereby granted, free of charge, to any person obtaining
5 5 // a copy of this software and associated documentation files (the
6 6 // "Software"), to deal in the Software without restriction, including
@@ -8,10 +8,10 @@
8 8 // distribute, sublicense, and/or sell copies of the Software, and to
9 9 // permit persons to whom the Software is furnished to do so, subject to
10 10 // the following conditions:
11   -//
  11 +//
12 12 // The above copyright notice and this permission notice shall be
13 13 // included in all copies or substantial portions of the Software.
14   -//
  14 +//
15 15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -23,7 +23,7 @@
23 23 // CreditCard.validate('1111 2222 3333 4444') -> true/false
24 24 // the given string is automatically stripped of whitespace, so it can be
25 25 // plugged directly into form validations
26   -//
  26 +//
27 27 // The following things are tested:
28 28 // 1. does the luhn validation code add up? (see http://en.wikipedia.org/wiki/Luhn_algorithm)
29 29 // 2. does the number range and length seem right? (see http://en.wikipedia.org/wiki/Bank_card_number)
@@ -64,7 +64,7 @@ var CreditCard = {
64 64 return number.gsub(/\s/,'');
65 65 },
66 66 type: function(number) {
67   - for(card in CreditCard.CARDS)
  67 + for(var card in CreditCard.CARDS)
68 68 if(CreditCard['is'+card](number)) return card;
69 69 }
70 70 };
2  creditcard.min.js
... ... @@ -1 +1 @@
1   -var CreditCard={CARDS:{Visa:/^4[0-9]{12}(?:[0-9]{3})?$/,MasterCard:/^5[1-5][0-9]{14}$/,DinersClub:/^3(?:0[0-5]|[68][0-9])[0-9]{11}$/,Amex:/^3[47][0-9]{13}$/,Discover:/^6(?:011|5[0-9]{2})[0-9]{12}$/},TEST_NUMBERS:$w("378282246310005 371449635398431 378734493671000 30569309025904 38520000023237 6011111111111117 6011000990139424 5555555555554444 5105105105105100 4111111111111111 4012888888881881 4222222222222"),validate:function(a){return CreditCard.verifyLuhn10(a)&&!!CreditCard.type(a)&&!CreditCard.isTestNumber(a)},verifyLuhn10:function(a){return $A(CreditCard.strip(a)).reverse().inject(0,function(a,b,c){return a+$A((parseInt(b)*[1,2][c%2]).toString()).inject(0,function(a,b){return a+parseInt(b)})})%10==0},isTestNumber:function(a){return CreditCard.TEST_NUMBERS.include(CreditCard.strip(a))},strip:function(a){return a.gsub(/\s/,"")},type:function(a){for(card in CreditCard.CARDS)if(CreditCard["is"+card](a))return card}};(function(){for(var a in CreditCard.CARDS)CreditCard["is"+a]=function(a,b){return CreditCard.CARDS[a].test(CreditCard.strip(b))}.curry(a)})()
  1 +var CreditCard={CARDS:{Visa:/^4[0-9]{12}(?:[0-9]{3})?$/,MasterCard:/^5[1-5][0-9]{14}$/,DinersClub:/^3(?:0[0-5]|[68][0-9])[0-9]{11}$/,Amex:/^3[47][0-9]{13}$/,Discover:/^6(?:011|5[0-9]{2})[0-9]{12}$/},TEST_NUMBERS:$w("378282246310005 371449635398431 378734493671000 30569309025904 38520000023237 6011111111111117 6011000990139424 5555555555554444 5105105105105100 4111111111111111 4012888888881881 4222222222222"),validate:function(a){return CreditCard.verifyLuhn10(a)&&!!CreditCard.type(a)&&!CreditCard.isTestNumber(a)},verifyLuhn10:function(a){return($A(CreditCard.strip(a)).reverse().inject(0,function(b,d,c){return b+$A((parseInt(d)*[1,2][c%2]).toString()).inject(0,function(e,f){return e+parseInt(f)})})%10==0)},isTestNumber:function(a){return CreditCard.TEST_NUMBERS.include(CreditCard.strip(a))},strip:function(a){return a.gsub(/\s/,"")},type:function(b){for(var a in CreditCard.CARDS){if(CreditCard["is"+a](b)){return a}}}};(function(){for(var a in CreditCard.CARDS){CreditCard["is"+a]=function(b,c){return CreditCard.CARDS[b].test(CreditCard.strip(c))}.curry(a)}})();

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.