summaryrefslogtreecommitdiff
path: root/includes/js/dojox/validate/creditCard.js
diff options
context:
space:
mode:
authormensonge <mensonge@b3834d28-1941-0410-a4f8-b48e95affb8f>2008-11-13 09:49:11 +0000
committermensonge <mensonge@b3834d28-1941-0410-a4f8-b48e95affb8f>2008-11-13 09:49:11 +0000
commite44a7e37b6c7b5961adaffc62b9042b8d442938e (patch)
tree95b67c356e93163467db2451f2b8cce84ed5d582 /includes/js/dojox/validate/creditCard.js
parenta62b9742ee5e28bcec6872d88f50f25b820914f6 (diff)
downloadsemanticscuttle-e44a7e37b6c7b5961adaffc62b9042b8d442938e.tar.gz
semanticscuttle-e44a7e37b6c7b5961adaffc62b9042b8d442938e.tar.bz2
New feature: basic Ajax suggestion for tags and implementation of Dojo toolkit
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@151 b3834d28-1941-0410-a4f8-b48e95affb8f
Diffstat (limited to 'includes/js/dojox/validate/creditCard.js')
-rw-r--r--includes/js/dojox/validate/creditCard.js92
1 files changed, 92 insertions, 0 deletions
diff --git a/includes/js/dojox/validate/creditCard.js b/includes/js/dojox/validate/creditCard.js
new file mode 100644
index 0000000..903aab1
--- /dev/null
+++ b/includes/js/dojox/validate/creditCard.js
@@ -0,0 +1,92 @@
+if(!dojo._hasResource["dojox.validate.creditCard"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
+dojo._hasResource["dojox.validate.creditCard"] = true;
+dojo.provide("dojox.validate.creditCard");
+
+dojo.require("dojox.validate._base");
+
+/*
+ Validates Credit Cards using account number rules in conjunction with the Luhn algorigthm
+
+ */
+
+dojox.validate.isValidCreditCard = function(/*String|Int*/value, /*String*/ccType){
+ //Summary:
+ // checks if ccType matches the # scheme in value, and if Luhn checksum is accurate (unless its an Enroute card, the checkSum is skipped)
+
+ //Value: Boolean
+ return ((ccType.toLowerCase() == 'er' || dojox.validate.isValidLuhn(value)) &&
+ dojox.validate.isValidCreditCardNumber(value,ccType.toLowerCase())); //Boolean
+}
+
+dojox.validate.isValidCreditCardNumber = function(/*String|Int*/value,/*String?*/ccType){
+ // summary:
+ // checks if value matches the pattern for that card or any card types if none is specified
+ //
+ // value: Boolean
+ // CC #, white spaces and dashes are ignored
+ //
+ // ccType: String?
+ // one of the values in cardinfo -- if Omitted it it returns a | delimited string of matching card types, or false if no matches found
+
+ value = String(value).replace(/[- ]/g,''); //ignore dashes and whitespaces
+
+ /* FIXME: not sure on all the abbreviations for credit cards,below is what each stands for atleast to my knowledge
+ mc: Mastercard
+ ec: Eurocard
+ vi: Visa
+ ax: American Express
+ dc: Diners Club
+ bl: Carte Blanch
+ di: Discover
+ jcb: JCB
+ er: Enroute
+ */
+ var cardinfo = {
+ 'mc':'5[1-5][0-9]{14}','ec':'5[1-5][0-9]{14}','vi':'4(?:[0-9]{12}|[0-9]{15})',
+ 'ax':'3[47][0-9]{13}', 'dc':'3(?:0[0-5][0-9]{11}|[68][0-9]{12})',
+ 'bl':'3(?:0[0-5][0-9]{11}|[68][0-9]{12})','di':'6011[0-9]{12}',
+ 'jcb':'(?:3[0-9]{15}|(2131|1800)[0-9]{11})','er':'2(?:014|149)[0-9]{11}'
+ };
+ if(ccType){
+ var expr = cardinfo[ccType.toLowerCase()];
+ return expr ? !!(value.match(cardinfo[ccType.toLowerCase()])) : false; // boolean
+ }
+ var results=[];
+ for(var p in cardinfo){
+ if(value.match('^'+cardinfo[p]+'$')){
+ results.push(p);
+ }
+ }
+ return results.length ? results.join('|') : false; // string | boolean
+}
+
+dojox.validate.isValidCvv = function(/*String|Int*/value, /*String*/ccType) {
+ //Summary:
+ // returns true if the security code (CCV) matches the correct format for supplied ccType
+
+ //Value: Boolean
+
+ if(typeof value!='string'){
+ value=String(value);
+ }
+ var format;
+ switch (ccType.toLowerCase()){
+ case 'mc':
+ case 'ec':
+ case 'vi':
+ case 'di':
+ format = '###';
+ break;
+ case 'ax':
+ format = '####';
+ break;
+ default:
+ return false; //Boolean
+ }
+ var flags = {format:format};
+ //FIXME? Why does isNumberFormat take an object for flags when its only parameter is either a string or an array inside the object?
+ //FIXME: um... just check value.length?
+ return (value.length == format.length && dojox.validate.isNumberFormat(value, flags)); //Boolean
+}
+
+}