root / trunk / web / dojo / dojox / validate / _base.js @ 9
History | View | Annotate | Download (1.65 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._base"]){ |
9 |
dojo._hasResource["dojox.validate._base"]=true; |
10 |
dojo.provide("dojox.validate._base");
|
11 |
dojo.experimental("dojox.validate");
|
12 |
dojo.require("dojo.regexp");
|
13 |
dojo.require("dojo.number");
|
14 |
dojo.require("dojox.validate.regexp");
|
15 |
dojox.validate.isText=function(_1,_2){ |
16 |
_2=(typeof _2=="object")?_2:{}; |
17 |
if(/^\s*$/.test(_1)){ |
18 |
return false; |
19 |
} |
20 |
if(typeof _2.length=="number"&&_2.length!=_1.length){ |
21 |
return false; |
22 |
} |
23 |
if(typeof _2.minlength=="number"&&_2.minlength>_1.length){ |
24 |
return false; |
25 |
} |
26 |
if(typeof _2.maxlength=="number"&&_2.maxlength<_1.length){ |
27 |
return false; |
28 |
} |
29 |
return true; |
30 |
}; |
31 |
dojox.validate._isInRangeCache={}; |
32 |
dojox.validate.isInRange=function(_3,_4){ |
33 |
_3=dojo.number.parse(_3,_4); |
34 |
if(isNaN(_3)){
|
35 |
return false; |
36 |
} |
37 |
_4=(typeof _4=="object")?_4:{}; |
38 |
var _5=(typeof _4.max=="number")?_4.max:Infinity,_6=(typeof _4.min=="number")?_4.min:-Infinity,_7=(typeof _4.decimal=="string")?_4.decimal:".",_8=dojox.validate._isInRangeCache,_9=_3+"max"+_5+"min"+_6+"dec"+_7; |
39 |
if(typeof _8[_9]!="undefined"){ |
40 |
return _8[_9];
|
41 |
} |
42 |
_8[_9]=!(_3<_6||_3>_5); |
43 |
return _8[_9];
|
44 |
}; |
45 |
dojox.validate.isNumberFormat=function(_a,_b){ |
46 |
var re=new RegExp("^"+dojox.validate.regexp.numberFormat(_b)+"$","i"); |
47 |
return re.test(_a);
|
48 |
}; |
49 |
dojox.validate.isValidLuhn=function(_c){ |
50 |
var _d=0,_e,_f; |
51 |
if(!dojo.isString(_c)){
|
52 |
_c=String(_c); |
53 |
} |
54 |
_c=_c.replace(/[- ]/g,""); |
55 |
_e=_c.length%2;
|
56 |
for(var i=0;i<_c.length;i++){ |
57 |
_f=parseInt(_c.charAt(i)); |
58 |
if(i%2==_e){ |
59 |
_f*=2;
|
60 |
} |
61 |
if(_f>9){ |
62 |
_f-=9;
|
63 |
} |
64 |
_d+=_f; |
65 |
} |
66 |
return !(_d%10); |
67 |
}; |
68 |
} |