X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Ftiny_mce%2Futils%2Fvalidate.js;h=27cbfab811e317865dfbda1c690b09c88d3b7b9b;hb=b05f4eef4014db3885787ef15107cba93c932ac9;hp=95ae4d37e9607596d53b2e79a73989a34140e5c6;hpb=26a4a07bdacdaa7013bf45cc235df207708acfde;p=citadel.git diff --git a/webcit/tiny_mce/utils/validate.js b/webcit/tiny_mce/utils/validate.js index 95ae4d37e..27cbfab81 100644 --- a/webcit/tiny_mce/utils/validate.js +++ b/webcit/tiny_mce/utils/validate.js @@ -1,50 +1,252 @@ /** - * $RCSfile: validate.js,v $ - * $Revision: 1.2 $ - * $Date: 2005/08/13 12:20:37 $ + * validate.js * - * Various form validation methods. + * Copyright 2009, Moxiecode Systems AB + * Released under LGPL License. * - * @author Moxiecode - * @copyright Copyright © 2005, Moxiecode Systems AB, All rights reserved. + * License: http://tinymce.moxiecode.com/license + * Contributing: http://tinymce.moxiecode.com/contributing */ -function testRegExp(form_name, element_name, re) { - return new RegExp(re).test(document.forms[form_name].elements[element_name].value); -} +/** + // String validation: + + if (!Validator.isEmail('myemail')) + alert('Invalid email.'); + + // Form validation: + + var f = document.forms['myform']; + + if (!Validator.isEmail(f.myemail)) + alert('Invalid email.'); +*/ + +var Validator = { + isEmail : function(s) { + return this.test(s, '^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+@[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$'); + }, + + isAbsUrl : function(s) { + return this.test(s, '^(news|telnet|nttp|file|http|ftp|https)://[-A-Za-z0-9\\.]+\\/?.*$'); + }, + + isSize : function(s) { + return this.test(s, '^[0-9.]+(%|in|cm|mm|em|ex|pt|pc|px)?$'); + }, + + isId : function(s) { + return this.test(s, '^[A-Za-z_]([A-Za-z0-9_])*$'); + }, + + isEmpty : function(s) { + var nl, i; + + if (s.nodeName == 'SELECT' && s.selectedIndex < 1) + return true; + + if (s.type == 'checkbox' && !s.checked) + return true; + + if (s.type == 'radio') { + for (i=0, nl = s.form.elements; i parseInt(v)) + st = this.mark(f, n); + } + } + + return st; + }, + + hasClass : function(n, c, d) { + return new RegExp('\\b' + c + (d ? '[0-9]+' : '') + '\\b', 'g').test(n.className); + }, + + getNum : function(n, c) { + c = n.className.match(new RegExp('\\b' + c + '([0-9]+)\\b', 'g'))[0]; + c = c.replace(/[^0-9]/g, ''); + + return c; + }, -function validateString(form_name, element_name) { - return (document.forms[form_name].elements[element_name].value.length > 0); -} + addClass : function(n, c, b) { + var o = this.removeClass(n, c); + n.className = b ? c + (o != '' ? (' ' + o) : '') : (o != '' ? (o + ' ') : '') + c; + }, -function validateSelection(form_name, element_name) { - return (document.forms[form_name].elements[element_name].selectedIndex > 0); -} + removeClass : function(n, c) { + c = n.className.replace(new RegExp("(^|\\s+)" + c + "(\\s+|$)"), ' '); + return n.className = c != ' ' ? c : ''; + }, -function validateCheckBox(form_name, element_name) { - return document.forms[form_name].elements[element_name].checked; -} + tags : function(f, s) { + return f.getElementsByTagName(s); + }, -function validateCleanString(form_name, element_name) { - return testRegExp(form_name, element_name, '^[A-Za-z0-9_]+$'); -} + mark : function(f, n) { + var s = this.settings; -function validateEmail(form_name, element_name) { - return testRegExp(form_name, element_name, '^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+@[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$'); -} + this.addClass(n, s.invalid_cls); + n.setAttribute('aria-invalid', 'true'); + this.markLabels(f, n, s.invalid_cls); -function validateAbsUrl(form_name, element_name) { - return testRegExp(form_name, element_name, '^(news|telnet|nttp|file|http|ftp|https)://[-A-Za-z0-9\\.]+$'); -} + return false; + }, -function validateNumber(form_name, element_name, allow_blank) { - return (!allow_blank && value == '') ? false : testRegExp(form_name, element_name, '^-?[0-9]*\\.?[0-9]*$'); -} + markLabels : function(f, n, ic) { + var nl, i; -function validateSize(form_name, element_name,) { - return testRegExp(form_name, element_name, '^[0-9]+(px|%)?$'); -} + nl = this.tags(f, "label"); + for (i=0; i