| Line 72... |
Line 72... |
| 72 |
|
72 |
|
| 73 |
//
|
73 |
//
|
| 74 |
// Validate Forms
|
74 |
// Validate Forms
|
| 75 |
// Arguments:
|
75 |
// Arguments:
|
| 76 |
// --Silent - Optional. Supresses alert
|
76 |
// --Silent - Optional. Supresses alert
|
| - |
|
77 |
// --NoPrefix - Optional. Supresses Message Prefix
|
| 77 |
// Triplets - Zero or more triplets.
|
78 |
// Triplets - Zero or more triplets.
|
| 78 |
// Eg: 'FRpkgName','Package Name','RisPackage'
|
79 |
// Eg: 'FRpkgName','Package Name','RisPackage'
|
| 79 |
// FormObject - Form Object ID
|
80 |
// FormObject - Form Object ID
|
| 80 |
// TextPrefix - Error message Prefix
|
81 |
// TextPrefix - Error message Prefix
|
| 81 |
// TestType - Type of test to perfom.
|
82 |
// TestType - Type of test to perfom.
|
| Line 84... |
Line 85... |
| 84 |
function MM_validateForm() {
|
85 |
function MM_validateForm() {
|
| 85 |
var ii,p,pl,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
|
86 |
var ii,p,pl,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
|
| 86 |
var REresults;
|
87 |
var REresults;
|
| 87 |
var pass,passc;
|
88 |
var pass,passc;
|
| 88 |
var showAlert = true;
|
89 |
var showAlert = true;
|
| - |
|
90 |
var showPrefix = true;
|
| - |
|
91 |
var prefix;
|
| 89 |
|
92 |
|
| 90 |
// Other general validations
|
93 |
// Other general validations
|
| 91 |
var cleanStrRE = /^[0-9a-z_\.\(\)\-]+$/i;
|
94 |
var cleanStrRE = /^[0-9a-z_\.\(\)\-]+$/i;
|
| 92 |
var pkgRE = /^[a-z][a-z0-9_-]*[a-z0-9]$/i;
|
95 |
var pkgRE = /^[a-z][a-z0-9_-]*[a-z0-9]$/i;
|
| 93 |
var versionRE = /^[0-9a-z_\.\(\)\-]+$/i;
|
96 |
var versionRE = /^[0-9a-z_\.\(\)\-]+$/i;
|
| Line 101... |
Line 104... |
| 101 |
for (ii=0; ii<(args.length-2) && typeof(args[ii]) === 'string' && args[ii].indexOf('--') == 0; ii++) {
|
104 |
for (ii=0; ii<(args.length-2) && typeof(args[ii]) === 'string' && args[ii].indexOf('--') == 0; ii++) {
|
| 102 |
switch(args[ii].toLowerCase()) {
|
105 |
switch(args[ii].toLowerCase()) {
|
| 103 |
case "--silent" :
|
106 |
case "--silent" :
|
| 104 |
showAlert = false;
|
107 |
showAlert = false;
|
| 105 |
break;
|
108 |
break;
|
| - |
|
109 |
case "--noprefix" :
|
| - |
|
110 |
showPrefix = false;
|
| - |
|
111 |
break;
|
| 106 |
}
|
112 |
}
|
| 107 |
}
|
113 |
}
|
| 108 |
|
114 |
|
| 109 |
// Iterate over arguments
|
115 |
// Iterate over arguments
|
| 110 |
// These are in triplets
|
116 |
// These are in triplets
|
| Line 116... |
Line 122... |
| 116 |
test=args[ii+2];
|
122 |
test=args[ii+2];
|
| 117 |
if ( typeof(args[ii]) === 'string' ) {
|
123 |
if ( typeof(args[ii]) === 'string' ) {
|
| 118 |
val=MM_findObj(args[ii]);
|
124 |
val=MM_findObj(args[ii]);
|
| 119 |
if (val) {
|
125 |
if (val) {
|
| 120 |
val=val.value;
|
126 |
val=val.value;
|
| - |
|
127 |
prefix = showPrefix ? val + ' - ' + nm : '';
|
| 121 |
|
128 |
|
| 122 |
if (val!="") {
|
129 |
if (val!="") {
|
| 123 |
if (test.indexOf('isEmail')!=-1) {
|
130 |
if (test.indexOf('isEmail')!=-1) {
|
| 124 |
p=val.indexOf('@');
|
131 |
p=val.indexOf('@');
|
| 125 |
if (p<1 || p==(val.length-1) || test.charAt(0) == '@') errors+='- '+nm+' must contain an e-mail address.\n';
|
132 |
if (p<1 || p==(val.length-1) || test.charAt(0) == '@') errors+='- '+nm+' must contain an e-mail address.\n';
|
| Line 140... |
Line 147... |
| 140 |
}
|
147 |
}
|
| 141 |
}
|
148 |
}
|
| 142 |
|
149 |
|
| 143 |
if (test.indexOf('isPackage')!=-1) {
|
150 |
if (test.indexOf('isPackage')!=-1) {
|
| 144 |
REresults = val.search(pkgRE);
|
151 |
REresults = val.search(pkgRE);
|
| 145 |
if (REresults < 0) errors += val + ' - '+nm+' is not valid. Valid characters are A-Z a-z 0-9 - _\n'
|
152 |
if (REresults < 0) errors += prefix + ' is not valid. Valid characters are A-Z a-z 0-9 - _\n'
|
| 146 |
+ 'Names must start with a letter and cannot contain spaces or symbols other than - and _\n';
|
153 |
+ 'Names must start with a letter and cannot contain spaces or symbols other than - and _\n';
|
| 147 |
}
|
154 |
}
|
| 148 |
|
155 |
|
| 149 |
if (test.indexOf('isCleanStr')!=-1) {
|
156 |
if (test.indexOf('isCleanStr')!=-1) {
|
| 150 |
REresults = val.search(cleanStrRE);
|
157 |
REresults = val.search(cleanStrRE);
|
| 151 |
if (REresults < 0) errors += val + '- '+nm+' uses invalid character. Allowed characters are A-Z a-z 0-9 . - _\n';
|
158 |
if (REresults < 0) errors += prefix + ' uses invalid character. Allowed characters are A-Z a-z 0-9 . - _\n';
|
| 152 |
}
|
159 |
}
|
| 153 |
|
160 |
|
| 154 |
if (test.indexOf('isVersionStr')!=-1) {
|
161 |
if (test.indexOf('isVersionStr')!=-1) {
|
| 155 |
REresults = val.search(versionRE);
|
162 |
REresults = val.search(versionRE);
|
| 156 |
if (REresults < 0) errors += val + '- '+nm+' uses invalid character. Allowed characters are A-Z a-z 0-9 . - _\n';
|
163 |
if (REresults < 0) errors += prefix + ' uses invalid character. Allowed characters are A-Z a-z 0-9 . - _\n';
|
| 157 |
}
|
164 |
}
|
| 158 |
|
165 |
|
| 159 |
if (test.indexOf('isPatchVersionStr')!=-1) {
|
166 |
if (test.indexOf('isPatchVersionStr')!=-1) {
|
| 160 |
if ( !re_patch_ver_format.test(val) ) {
|
167 |
if ( !re_patch_ver_format.test(val) ) {
|
| 161 |
errors += val + '- '+nm+' is not of form (integer).(integer).(integer).p(integer).(extension)\n';
|
168 |
errors += prefix + ' is not of form (integer).(integer).(integer).p(integer).(extension)\n';
|
| 162 |
}
|
169 |
}
|
| 163 |
}
|
170 |
}
|
| 164 |
|
171 |
|
| 165 |
if (test.indexOf('isCCPath')!=-1) {
|
172 |
if (test.indexOf('isCCPath')!=-1) {
|
| 166 |
var CCPathRE = /^\\|\/[a-z]+[0-9a-z_\.\-\\\/ ]+$/i;
|
173 |
var CCPathRE = /^\\|\/[a-z]+[0-9a-z_\.\-\\\/ ]+$/i;
|
| 167 |
|
174 |
|
| 168 |
REresults = val.search(/^(\\|\/)/);
|
175 |
REresults = val.search(/^(\\|\/)/);
|
| 169 |
if (REresults < 0) errors += val + '- '+nm+' must begin with \\ or /\n';
|
176 |
if (REresults < 0) errors += prefix + ' must begin with \\ or /\n';
|
| 170 |
|
177 |
|
| 171 |
REresults = val.search(CCPathRE);
|
178 |
REresults = val.search(CCPathRE);
|
| 172 |
if (REresults < 0) errors += val + '- '+nm+' uses invalid character.\nAllowed characters are \\ / A-Z a-z 0-9 . - _ SPACE\n';
|
179 |
if (REresults < 0) errors += prefix + ' uses invalid character.\nAllowed characters are \\ / A-Z a-z 0-9 . - _ SPACE\n';
|
| 173 |
}
|
180 |
}
|
| 174 |
|
181 |
|
| 175 |
if (test.indexOf('isCCLabel')!=-1) {
|
182 |
if (test.indexOf('isCCLabel')!=-1) {
|
| 176 |
var CCLabelRE = /^[0-9a-z_\.\-]+$/i;
|
183 |
var CCLabelRE = /^[0-9a-z_\.\-]+$/i;
|
| 177 |
|
184 |
|
| 178 |
REresults = val.search(CCLabelRE);
|
185 |
REresults = val.search(CCLabelRE);
|
| 179 |
if (REresults < 0) errors += val + '- '+nm+' uses invalid character.\nAllowed characters are A-Z a-z 0-9 . - _\n';
|
186 |
if (REresults < 0) errors += prefix + ' uses invalid character.\nAllowed characters are A-Z a-z 0-9 . - _\n';
|
| 180 |
}
|
187 |
}
|
| 181 |
|
188 |
|
| 182 |
if (test.indexOf('isSVNTag')!=-1) {
|
189 |
if (test.indexOf('isSVNTag')!=-1) {
|
| 183 |
// Subversion Tag validation
|
190 |
// Subversion Tag validation
|
| 184 |
var SVNTagValidPeg = /^@?\d+$/;
|
191 |
var SVNTagValidPeg = /^@?\d+$/;
|
| Line 187... |
Line 194... |
| 187 |
if ( val.search(SVNTagValidPeg) < 0) {
|
194 |
if ( val.search(SVNTagValidPeg) < 0) {
|
| 188 |
|
195 |
|
| 189 |
var stripped;
|
196 |
var stripped;
|
| 190 |
stripped = val.replace (/@\d+$/,"");
|
197 |
stripped = val.replace (/@\d+$/,"");
|
| 191 |
if (stripped.search(SVNTagRE) < 0)
|
198 |
if (stripped.search(SVNTagRE) < 0)
|
| 192 |
errors += val + '- '+nm+' uses invalid character. Allowed characters are A-Z a-z 0-9 . - _\n';
|
199 |
errors += prefix + ' uses invalid character. Allowed characters are A-Z a-z 0-9 . - _\n';
|
| 193 |
}
|
200 |
}
|
| 194 |
}
|
201 |
}
|
| 195 |
|
202 |
|
| 196 |
if (test.indexOf('isSVNPegTag')!=-1 && ! errors) {
|
203 |
if (test.indexOf('isSVNPegTag')!=-1 && ! errors) {
|
| 197 |
// Subversion Tag has peg - Must have done valid check first
|
204 |
// Subversion Tag has peg - Must have done valid check first
|
| 198 |
var SVNTagPegged = /@?\d+$/;
|
205 |
var SVNTagPegged = /@?\d+$/;
|
| 199 |
|
206 |
|
| 200 |
if ( val.search(SVNTagPegged) < 0) {
|
207 |
if ( val.search(SVNTagPegged) < 0) {
|
| 201 |
errors += val + '- '+nm+' Must be pegged for Manually Versioned Package. ie:tag@pegNumber\n';
|
208 |
errors += prefix + ' Must be pegged for Manually Versioned Package. ie:tag@pegNumber\n';
|
| 202 |
}
|
209 |
}
|
| 203 |
}
|
210 |
}
|
| 204 |
|
211 |
|
| 205 |
if (test.indexOf('isSVNPath')!=-1) {
|
212 |
if (test.indexOf('isSVNPath')!=-1) {
|
| 206 |
// Subversion Base Path validation
|
213 |
// Subversion Base Path validation
|
| Line 211... |
Line 218... |
| 211 |
var SVNTagInValidTrunkAnywhereRE = /\/trunk\//i;
|
218 |
var SVNTagInValidTrunkAnywhereRE = /\/trunk\//i;
|
| 212 |
var SVNTagValidTagAnywhereRE = /^.*\/tags\/.*$/i;
|
219 |
var SVNTagValidTagAnywhereRE = /^.*\/tags\/.*$/i;
|
| 213 |
var SVNTagValidTagBranchPathRE = /^.*\/branches\/.*\/.*$/i;
|
220 |
var SVNTagValidTagBranchPathRE = /^.*\/branches\/.*\/.*$/i;
|
| 214 |
|
221 |
|
| 215 |
if (val.search(SVNTagValidCharsRE) < 0)
|
222 |
if (val.search(SVNTagValidCharsRE) < 0)
|
| 216 |
errors += val + ' - '+nm+' uses invalid character. Allowed characters are / A-Z a-z 0-9 . - _\n';
|
223 |
errors += prefix + ' uses invalid character. Allowed characters are / A-Z a-z 0-9 . - _\n';
|
| 217 |
else if (val.search(SVNTagInValidSlashAtBOL) >= 0)
|
224 |
else if (val.search(SVNTagInValidSlashAtBOL) >= 0)
|
| 218 |
errors += val + ' - '+nm+' begins with a /. This is not allowed.\n';
|
225 |
errors += prefix + ' begins with a /. This is not allowed.\n';
|
| 219 |
else if (val.search(SVNTagInValidSlashAtEOL) >= 0)
|
226 |
else if (val.search(SVNTagInValidSlashAtEOL) >= 0)
|
| 220 |
errors += val + ' - '+nm+' ends with a /. This is not allowed.\n';
|
227 |
errors += prefix + ' ends with a /. This is not allowed.\n';
|
| 221 |
else if (val.search(SVNTagInValidSlash) >= 0)
|
228 |
else if (val.search(SVNTagInValidSlash) >= 0)
|
| 222 |
errors += val + ' - '+nm+' uses //. This is not allowed.\n';
|
229 |
errors += prefix + ' uses //. This is not allowed.\n';
|
| 223 |
else if (val.search(SVNTagValidTagAnywhereRE) >= 0)
|
230 |
else if (val.search(SVNTagValidTagAnywhereRE) >= 0)
|
| 224 |
errors += val + ' - '+nm+' contains /tags/. This is not allowed.\n';
|
231 |
errors += prefix + ' contains /tags/. This is not allowed.\n';
|
| 225 |
else if (val.search(SVNTagInValidTrunkAnywhereRE) >= 0)
|
232 |
else if (val.search(SVNTagInValidTrunkAnywhereRE) >= 0)
|
| 226 |
errors += val + ' - '+nm+' contains /trunk/. This is not allowed.\n';
|
233 |
errors += prefix + ' contains /trunk/. This is not allowed.\n';
|
| 227 |
else if (val.search(SVNTagValidTagBranchPathRE) >= 0)
|
234 |
else if (val.search(SVNTagValidTagBranchPathRE) >= 0)
|
| 228 |
errors += val + ' - '+nm+' contains branch with multiple sub directories. This is not allowed.\n';
|
235 |
errors += prefix + ' contains branch with multiple sub directories. This is not allowed.\n';
|
| 229 |
else {
|
236 |
else {
|
| 230 |
var bits = val.split("/");
|
237 |
var bits = val.split("/");
|
| 231 |
if ( bits.length < 4 )
|
238 |
if ( bits.length < 4 )
|
| 232 |
errors += val + ' - Must contain at least 4 path items.\n';
|
239 |
errors += prefix + ' - Must contain at least 4 path items.\n';
|
| 233 |
|
240 |
else
|
| - |
|
241 |
{
|
| 234 |
var ttbcount = 0;
|
242 |
var ttbcount = 0;
|
| 235 |
var i
|
243 |
var i
|
| 236 |
for (i=0; i < bits.length; i++ )
|
244 |
for (i=0; i < bits.length; i++ )
|
| 237 |
{
|
245 |
{
|
| 238 |
var el = bits[i];
|
246 |
var el = bits[i];
|
| 239 |
if ( el == 'tags') ttbcount++;
|
247 |
if ( el == 'tags') ttbcount++;
|
| 240 |
if ( el == 'trunk') ttbcount++;
|
248 |
if ( el == 'trunk') ttbcount++;
|
| 241 |
if ( el == 'branches') ttbcount++;
|
249 |
if ( el == 'branches') ttbcount++;
|
| 242 |
}
|
250 |
}
|
| 243 |
if ( ttbcount != 1 )
|
251 |
if ( ttbcount != 1 )
|
| 244 |
errors += val + ' - '+nm+' must contain exactly one of tags, trunk or branches. It contains '+ttbcount+'.\n';
|
252 |
errors += prefix + ' must contain exactly one of tags, trunk or branches. It contains '+ttbcount+'.\n';
|
| 245 |
|
253 |
|
| 246 |
if ( bits.pop() == 'branches' )
|
254 |
if ( bits.pop() == 'branches' )
|
| 247 |
errors += val + ' - '+nm+' must not end in branches.\n';
|
255 |
errors += prefix + ' must not end in branches.\n';
|
| - |
|
256 |
}
|
| 248 |
|
257 |
|
| 249 |
}
|
258 |
}
|
| 250 |
}
|
259 |
}
|
| 251 |
|
260 |
|
| 252 |
// No longer used in this simple form
|
261 |
// No longer used in this simple form
|
| 253 |
if (test.indexOf('isVersionNumber')!=-1) {
|
262 |
if (test.indexOf('isVersionNumber')!=-1) {
|
| 254 |
REresults = -1;
|
263 |
REresults = -1;
|
| 255 |
if (REresults < 0) errors += val + ' - '+nm+' isVersionNumber is no longer supported in this form';
|
264 |
if (REresults < 0) errors += prefix + ' isVersionNumber is no longer supported in this form';
|
| 256 |
}
|
265 |
}
|
| 257 |
|
266 |
|
| 258 |
if (test.indexOf('isURL')!=-1) {
|
267 |
if (test.indexOf('isURL')!=-1) {
|
| 259 |
REresults = val.match(urlRE);
|
268 |
REresults = val.match(urlRE);
|
| 260 |
if (REresults == null) errors += '"'+val+'" is not a valid URL.\n';
|
269 |
if (REresults == null) errors += '"'+val+'" is not a valid URL.\n';
|