root / trunk / web / dojo / dojox / validate / creditCard.js @ 12
History | View | Annotate | Download (1.43 KB)
1 |
/*
|
---|---|
2 |
Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
3 |
Available via Academic Free License >= 2.1 OR the modified BSD license.
|
4 |
see: http://dojotoolkit.org/license for details
|
5 |
*/
|
6 |
|
7 |
|
8 |
if(!dojo._hasResource["dojox.validate.creditCard"]){ |
9 |
dojo._hasResource["dojox.validate.creditCard"]=true; |
10 |
dojo.provide("dojox.validate.creditCard");
|
11 |
dojo.require("dojox.validate._base");
|
12 |
dojox.validate._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}"}; |
13 |
dojox.validate.isValidCreditCard=function(_1,_2){ |
14 |
return ((_2.toLowerCase()=="er"||dojox.validate.isValidLuhn(_1))&&dojox.validate.isValidCreditCardNumber(_1,_2.toLowerCase())); |
15 |
}; |
16 |
dojox.validate.isValidCreditCardNumber=function(_3,_4){ |
17 |
_3=String(_3).replace(/[- ]/g,""); |
18 |
var _5=dojox.validate._cardInfo,_6=[];
|
19 |
if(_4){
|
20 |
var _7="^"+_5[_4.toLowerCase()]+"$"; |
21 |
return _7?!!_3.match(_7):false; |
22 |
} |
23 |
for(var p in _5){ |
24 |
if(_3.match("^"+_5[p]+"$")){ |
25 |
_6.push(p); |
26 |
} |
27 |
} |
28 |
return _6.length?_6.join("|"):false; |
29 |
}; |
30 |
dojox.validate.isValidCvv=function(_8,_9){ |
31 |
if(!dojo.isString(_8)){
|
32 |
_8=String(_8); |
33 |
} |
34 |
var _a;
|
35 |
switch(_9.toLowerCase()){
|
36 |
case "mc": |
37 |
case "ec": |
38 |
case "vi": |
39 |
case "di": |
40 |
_a="###";
|
41 |
break;
|
42 |
case "ax": |
43 |
_a="####";
|
44 |
break;
|
45 |
} |
46 |
return !!_a&&_8.length&&dojox.validate.isNumberFormat(_8,{format:_a}); |
47 |
}; |
48 |
} |