Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / validate / regexp.js @ 12

History | View | Annotate | Download (4.38 KB)

1 9 andrej.cim
/*
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.regexp"]){
9
dojo._hasResource["dojox.validate.regexp"]=true;
10
dojo.provide("dojox.validate.regexp");
11
dojo.require("dojo.regexp");
12
dojo.mixin(dojox.validate.regexp,{ipAddress:function(_1){
13
_1=(typeof _1=="object")?_1:{};
14
if(typeof _1.allowDottedDecimal!="boolean"){
15
_1.allowDottedDecimal=true;
16
}
17
if(typeof _1.allowDottedHex!="boolean"){
18
_1.allowDottedHex=true;
19
}
20
if(typeof _1.allowDottedOctal!="boolean"){
21
_1.allowDottedOctal=true;
22
}
23
if(typeof _1.allowDecimal!="boolean"){
24
_1.allowDecimal=true;
25
}
26
if(typeof _1.allowHex!="boolean"){
27
_1.allowHex=true;
28
}
29
if(typeof _1.allowIPv6!="boolean"){
30
_1.allowIPv6=true;
31
}
32
if(typeof _1.allowHybrid!="boolean"){
33
_1.allowHybrid=true;
34
}
35
var _2="((\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.){3}(\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])";
36
var _3="(0[xX]0*[\\da-fA-F]?[\\da-fA-F]\\.){3}0[xX]0*[\\da-fA-F]?[\\da-fA-F]";
37
var _4="(0+[0-3][0-7][0-7]\\.){3}0+[0-3][0-7][0-7]";
38
var _5="(0|[1-9]\\d{0,8}|[1-3]\\d{9}|4[01]\\d{8}|42[0-8]\\d{7}|429[0-3]\\d{6}|"+"4294[0-8]\\d{5}|42949[0-5]\\d{4}|429496[0-6]\\d{3}|4294967[01]\\d{2}|42949672[0-8]\\d|429496729[0-5])";
39
var _6="0[xX]0*[\\da-fA-F]{1,8}";
40
var _7="([\\da-fA-F]{1,4}\\:){7}[\\da-fA-F]{1,4}";
41
var _8="([\\da-fA-F]{1,4}\\:){6}"+"((\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.){3}(\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])";
42
var a=[];
43
if(_1.allowDottedDecimal){
44
a.push(_2);
45
}
46
if(_1.allowDottedHex){
47
a.push(_3);
48
}
49
if(_1.allowDottedOctal){
50
a.push(_4);
51
}
52
if(_1.allowDecimal){
53
a.push(_5);
54
}
55
if(_1.allowHex){
56
a.push(_6);
57
}
58
if(_1.allowIPv6){
59
a.push(_7);
60
}
61
if(_1.allowHybrid){
62
a.push(_8);
63
}
64
var _9="";
65
if(a.length>0){
66
_9="("+a.join("|")+")";
67
}
68
return _9;
69
},host:function(_a){
70
_a=(typeof _a=="object")?_a:{};
71
if(typeof _a.allowIP!="boolean"){
72
_a.allowIP=true;
73
}
74
if(typeof _a.allowLocal!="boolean"){
75
_a.allowLocal=false;
76
}
77
if(typeof _a.allowPort!="boolean"){
78
_a.allowPort=true;
79
}
80
if(typeof _a.allowNamed!="boolean"){
81
_a.allowNamed=false;
82
}
83
var _b="(?:[\\da-zA-Z](?:[-\\da-zA-Z]{0,61}[\\da-zA-Z])?)";
84
var _c="(?:[a-zA-Z](?:[-\\da-zA-Z]{0,6}[\\da-zA-Z])?)";
85
var _d=_a.allowPort?"(\\:\\d+)?":"";
86
var _e="((?:"+_b+"\\.)+"+_c+"\\.?)";
87
if(_a.allowIP){
88
_e+="|"+dojox.validate.regexp.ipAddress(_a);
89
}
90
if(_a.allowLocal){
91
_e+="|localhost";
92
}
93
if(_a.allowNamed){
94
_e+="|^[^-][a-zA-Z0-9_-]*";
95
}
96
return "("+_e+")"+_d;
97
},url:function(_f){
98
_f=(typeof _f=="object")?_f:{};
99
if(!("scheme" in _f)){
100
_f.scheme=[true,false];
101
}
102
var _10=dojo.regexp.buildGroupRE(_f.scheme,function(q){
103
if(q){
104
return "(https?|ftps?)\\://";
105
}
106
return "";
107
});
108
var _11="(/(?:[^?#\\s/]+/)*(?:[^?#\\s/]+(?:\\?[^?#\\s/]*)?(?:#[A-Za-z][\\w.:-]*)?)?)?";
109
return _10+dojox.validate.regexp.host(_f)+_11;
110
},emailAddress:function(_12){
111
_12=(typeof _12=="object")?_12:{};
112
if(typeof _12.allowCruft!="boolean"){
113
_12.allowCruft=false;
114
}
115
_12.allowPort=false;
116
var _13="([!#-'*+\\-\\/-9=?A-Z^-~]+[.])*[!#-'*+\\-\\/-9=?A-Z^-~]+";
117
var _14=_13+"@"+dojox.validate.regexp.host(_12);
118
if(_12.allowCruft){
119
_14="<?(mailto\\:)?"+_14+">?";
120
}
121
return _14;
122
},emailAddressList:function(_15){
123
_15=(typeof _15=="object")?_15:{};
124
if(typeof _15.listSeparator!="string"){
125
_15.listSeparator="\\s;,";
126
}
127
var _16=dojox.validate.regexp.emailAddress(_15);
128
var _17="("+_16+"\\s*["+_15.listSeparator+"]\\s*)*"+_16+"\\s*["+_15.listSeparator+"]?\\s*";
129
return _17;
130
},numberFormat:function(_18){
131
_18=(typeof _18=="object")?_18:{};
132
if(typeof _18.format=="undefined"){
133
_18.format="###-###-####";
134
}
135
var _19=function(_1a){
136
return dojo.regexp.escapeString(_1a,"?").replace(/\?/g,"\\d?").replace(/#/g,"\\d");
137
};
138
return dojo.regexp.buildGroupRE(_18.format,_19);
139
}});
140
dojox.validate.regexp.ca={postalCode:function(){
141
return "([A-Z][0-9][A-Z] [0-9][A-Z][0-9])";
142
},province:function(){
143
return "(AB|BC|MB|NB|NL|NS|NT|NU|ON|PE|QC|SK|YT)";
144
}};
145
dojox.validate.regexp.us={state:function(_1b){
146
_1b=(typeof _1b=="object")?_1b:{};
147
if(typeof _1b.allowTerritories!="boolean"){
148
_1b.allowTerritories=true;
149
}
150
if(typeof _1b.allowMilitary!="boolean"){
151
_1b.allowMilitary=true;
152
}
153
var _1c="AL|AK|AZ|AR|CA|CO|CT|DE|DC|FL|GA|HI|ID|IL|IN|IA|KS|KY|LA|ME|MD|MA|MI|MN|MS|MO|MT|"+"NE|NV|NH|NJ|NM|NY|NC|ND|OH|OK|OR|PA|RI|SC|SD|TN|TX|UT|VT|VA|WA|WV|WI|WY";
154
var _1d="AS|FM|GU|MH|MP|PW|PR|VI";
155
var _1e="AA|AE|AP";
156
if(_1b.allowTerritories){
157
_1c+="|"+_1d;
158
}
159
if(_1b.allowMilitary){
160
_1c+="|"+_1e;
161
}
162
return "("+_1c+")";
163
}};
164
}