| 20 | | dojox.validate.isValidCreditCardNumber = function(/*String|Int*/value,/*String?*/ccType) { |
| 21 | | //Summary: |
| 22 | | // checks if the # matches the pattern for that card or any card types if none is specified |
| 23 | | // value == CC #, white spaces and dashes are ignored |
| 24 | | // ccType is of the values in cardinfo -- if Omitted it it returns a | delimited string of matching card types, or false if no matches found |
| 25 | | |
| 26 | | //Value: Boolean |
| 27 | | |
| 28 | | if(typeof value!='string'){ |
| 29 | | value = String(value); |
| 30 | | } |
| 31 | | value = value.replace(/[- ]/g,''); //ignore dashes and whitespaces |
| | 18 | |
| | 19 | dojox.validate.isValidCreditCardNumber = function(/*String|Int*/value,/*String?*/ccType){ |
| | 20 | // summary: |
| | 21 | // checks if value matches the pattern for that card or any card types if none is specified |
| | 22 | // |
| | 23 | // value: Boolean |
| | 24 | // CC #, white spaces and dashes are ignored |
| | 25 | // |
| | 26 | // ccType: String? |
| | 27 | // one of the values in cardinfo -- if Omitted it it returns a | delimited string of matching card types, or false if no matches found |
| | 28 | |
| | 29 | value = String(value).replace(/[- ]/g,''); //ignore dashes and whitespaces |
| | 30 | |
| | 42 | var cardinfo = { |
| | 43 | 'mc':'5[1-5][0-9]{14}','ec':'5[1-5][0-9]{14}','vi':'4(?:[0-9]{12}|[0-9]{15})', |
| | 44 | 'ax':'3[47][0-9]{13}', 'dc':'3(?:0[0-5][0-9]{11}|[68][0-9]{12})', |
| | 45 | 'bl':'3(?:0[0-5][0-9]{11}|[68][0-9]{12})','di':'6011[0-9]{12}', |
| | 46 | 'jcb':'(?:3[0-9]{15}|(2131|1800)[0-9]{11})','er':'2(?:014|149)[0-9]{11}' |
| | 47 | }; |
| | 48 | if(ccType){ |
| | 49 | var expr = cardinfo[ccType.toLowerCase()]; |
| | 50 | return expr ? !!(value.match(cardinfo[ccType.toLowerCase()])) : false; // boolean |
| | 51 | } |
| 44 | | var cardinfo = { |
| 45 | | 'mc':'5[1-5][0-9]{14}','ec':'5[1-5][0-9]{14}','vi':'4([0-9]{12}|[0-9]{15})', |
| 46 | | 'ax':'3[47][0-9]{13}', 'dc':'3(0[0-5][0-9]{11}|[68][0-9]{12})', |
| 47 | | 'bl':'3(0[0-5][0-9]{11}|[68][0-9]{12})','di':'6011[0-9]{12}', |
| 48 | | 'jcb':'(3[0-9]{15}|(2131|1800)[0-9]{11})','er':'2(014|149)[0-9]{11}' |
| 49 | | }; |
| 50 | | if(ccType&&dojo.indexOf(cardinfo,ccType.toLowerCase())){ |
| 51 | | return Boolean(value.match(cardinfo[ccType.toLowerCase()])); // boolean |
| 52 | | }else{ |
| 53 | | for(var p in cardinfo){ |
| 54 | | if(value.match('^'+cardinfo[p]+'$')!=null){ |
| 55 | | results.push(p); |
| 56 | | } |
| | 53 | for(var p in cardinfo){ |
| | 54 | if(value.match('^'+cardinfo[p]+'$')){ |
| | 55 | results.push(p); |