-
+ ED9F0CC271B65D37D635705ED13445530F66856AB09CAA28750F31903751FCB85B9D08F53FB9953908ECF1B16518EB4E10AAEBE205C3155662D96367C6725FD4
mp-wp/wp-includes/js/tinymce/utils/validate.js
(0 . 0)(1 . 218)
132195 /**
132196 * $Id: validate.js 758 2008-03-30 13:53:29Z spocke $
132197 *
132198 * Various form validation methods.
132199 *
132200 * @author Moxiecode
132201 */
132202
132203 /**
132204 // String validation:
132205
132206 if (!Validator.isEmail('myemail'))
132207 alert('Invalid email.');
132208
132209 // Form validation:
132210
132211 var f = document.forms['myform'];
132212
132213 if (!Validator.isEmail(f.myemail))
132214 alert('Invalid email.');
132215 */
132216
132217 var Validator = {
132218 isEmail : function(s) {
132219 return this.test(s, '^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+@[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$');
132220 },
132221
132222 isAbsUrl : function(s) {
132223 return this.test(s, '^(news|telnet|nttp|file|http|ftp|https)://[-A-Za-z0-9\\.]+\\/?.*$');
132224 },
132225
132226 isSize : function(s) {
132227 return this.test(s, '^[0-9]+(%|in|cm|mm|em|ex|pt|pc|px)?$');
132228 },
132229
132230 isId : function(s) {
132231 return this.test(s, '^[A-Za-z_]([A-Za-z0-9_])*$');
132232 },
132233
132234 isEmpty : function(s) {
132235 var nl, i;
132236
132237 if (s.nodeName == 'SELECT' && s.selectedIndex < 1)
132238 return true;
132239
132240 if (s.type == 'checkbox' && !s.checked)
132241 return true;
132242
132243 if (s.type == 'radio') {
132244 for (i=0, nl = s.form.elements; i<nl.length; i++) {
132245 if (nl[i].type == "radio" && nl[i].name == s.name && nl[i].checked)
132246 return false;
132247 }
132248
132249 return true;
132250 }
132251
132252 return new RegExp('^\\s*$').test(s.nodeType == 1 ? s.value : s);
132253 },
132254
132255 isNumber : function(s, d) {
132256 return !isNaN(s.nodeType == 1 ? s.value : s) && (!d || !this.test(s, '^-?[0-9]*\\.[0-9]*$'));
132257 },
132258
132259 test : function(s, p) {
132260 s = s.nodeType == 1 ? s.value : s;
132261
132262 return s == '' || new RegExp(p).test(s);
132263 }
132264 };
132265
132266 var AutoValidator = {
132267 settings : {
132268 id_cls : 'id',
132269 int_cls : 'int',
132270 url_cls : 'url',
132271 number_cls : 'number',
132272 email_cls : 'email',
132273 size_cls : 'size',
132274 required_cls : 'required',
132275 invalid_cls : 'invalid',
132276 min_cls : 'min',
132277 max_cls : 'max'
132278 },
132279
132280 init : function(s) {
132281 var n;
132282
132283 for (n in s)
132284 this.settings[n] = s[n];
132285 },
132286
132287 validate : function(f) {
132288 var i, nl, s = this.settings, c = 0;
132289
132290 nl = this.tags(f, 'label');
132291 for (i=0; i<nl.length; i++)
132292 this.removeClass(nl[i], s.invalid_cls);
132293
132294 c += this.validateElms(f, 'input');
132295 c += this.validateElms(f, 'select');
132296 c += this.validateElms(f, 'textarea');
132297
132298 return c == 3;
132299 },
132300
132301 invalidate : function(n) {
132302 this.mark(n.form, n);
132303 },
132304
132305 reset : function(e) {
132306 var t = ['label', 'input', 'select', 'textarea'];
132307 var i, j, nl, s = this.settings;
132308
132309 if (e == null)
132310 return;
132311
132312 for (i=0; i<t.length; i++) {
132313 nl = this.tags(e.form ? e.form : e, t[i]);
132314 for (j=0; j<nl.length; j++)
132315 this.removeClass(nl[j], s.invalid_cls);
132316 }
132317 },
132318
132319 validateElms : function(f, e) {
132320 var nl, i, n, s = this.settings, st = true, va = Validator, v;
132321
132322 nl = this.tags(f, e);
132323 for (i=0; i<nl.length; i++) {
132324 n = nl[i];
132325
132326 this.removeClass(n, s.invalid_cls);
132327
132328 if (this.hasClass(n, s.required_cls) && va.isEmpty(n))
132329 st = this.mark(f, n);
132330
132331 if (this.hasClass(n, s.number_cls) && !va.isNumber(n))
132332 st = this.mark(f, n);
132333
132334 if (this.hasClass(n, s.int_cls) && !va.isNumber(n, true))
132335 st = this.mark(f, n);
132336
132337 if (this.hasClass(n, s.url_cls) && !va.isAbsUrl(n))
132338 st = this.mark(f, n);
132339
132340 if (this.hasClass(n, s.email_cls) && !va.isEmail(n))
132341 st = this.mark(f, n);
132342
132343 if (this.hasClass(n, s.size_cls) && !va.isSize(n))
132344 st = this.mark(f, n);
132345
132346 if (this.hasClass(n, s.id_cls) && !va.isId(n))
132347 st = this.mark(f, n);
132348
132349 if (this.hasClass(n, s.min_cls, true)) {
132350 v = this.getNum(n, s.min_cls);
132351
132352 if (isNaN(v) || parseInt(n.value) < parseInt(v))
132353 st = this.mark(f, n);
132354 }
132355
132356 if (this.hasClass(n, s.max_cls, true)) {
132357 v = this.getNum(n, s.max_cls);
132358
132359 if (isNaN(v) || parseInt(n.value) > parseInt(v))
132360 st = this.mark(f, n);
132361 }
132362 }
132363
132364 return st;
132365 },
132366
132367 hasClass : function(n, c, d) {
132368 return new RegExp('\\b' + c + (d ? '[0-9]+' : '') + '\\b', 'g').test(n.className);
132369 },
132370
132371 getNum : function(n, c) {
132372 c = n.className.match(new RegExp('\\b' + c + '([0-9]+)\\b', 'g'))[0];
132373 c = c.replace(/[^0-9]/g, '');
132374
132375 return c;
132376 },
132377
132378 addClass : function(n, c, b) {
132379 var o = this.removeClass(n, c);
132380 n.className = b ? c + (o != '' ? (' ' + o) : '') : (o != '' ? (o + ' ') : '') + c;
132381 },
132382
132383 removeClass : function(n, c) {
132384 c = n.className.replace(new RegExp("(^|\\s+)" + c + "(\\s+|$)"), ' ');
132385 return n.className = c != ' ' ? c : '';
132386 },
132387
132388 tags : function(f, s) {
132389 return f.getElementsByTagName(s);
132390 },
132391
132392 mark : function(f, n) {
132393 var s = this.settings;
132394
132395 this.addClass(n, s.invalid_cls);
132396 this.markLabels(f, n, s.invalid_cls);
132397
132398 return false;
132399 },
132400
132401 markLabels : function(f, n, ic) {
132402 var nl, i;
132403
132404 nl = this.tags(f, "label");
132405 for (i=0; i<nl.length; i++) {
132406 if (nl[i].getAttribute("for") == n.id || nl[i].htmlFor == n.id)
132407 this.addClass(nl[i], ic);
132408 }
132409
132410 return null;
132411 }
132412 };