1/* This file is part of cbui. 2 * Copyright © 2010-2012 stiftung kulturserver.de ggmbh <[email protected]> 3 * 4 * cbui is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * cbui is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with cbui. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18/** 19 * validate input widgets according to classes defined on input fields (or assigned manually) 20 */ 21 22/** 23 * Validator base class. Handles life cycle 24 */ 25jQuery.CbValidate.validator = base2.Base.extend({ 26 constructor : function(widget) { 27 this.base(); 28 widget.validators.push(this); 29 }, 30 31 valid : function(widget) { 32 return true; 33 }, 34 35 destroy : function() {} 36}); 37 38/** 39 * makes sure a field is neither empty nor contains the predefined string. 40 */ 41jQuery.CbValidate.nonempty = jQuery.CbValidate.validator.extend({ 42 valid : function(widget) { 43 // attention: widget.value() could be true/false for checkboxes 44 return widget.value() != "" && 45 widget.value() != jQuery.CbWidgetRegistry.bricks[widget.texts.text]; 46 } 47}); 48 49/** 50 * makes sure a field contains an email address. 51 */ 52jQuery.CbValidate.email = jQuery.CbValidate.nonempty.extend({ 53 valid : function(widget) { 54 return this.base(widget) && 55 widget.value().match(/^[\w_\-\.]{1,}@[\w_\-\.]{2,}\.[\w]{2,22}$/); 56 } 57}); 58 59/** 60 * makes sure a field contains a valid account name. 61 */ 62jQuery.CbValidate.account = jQuery.CbValidate.email.extend({ 63 valid : function(widget) { 64 return widget.value().match(/^[a-zA-Z0-9][a-zA-Z0-9\-]{0,23}[a-zA-Z0-9]$/) || this.base(widget); 65 } 66}); 67 68/** 69 * makes sure a field contains a url. 70 */ 71jQuery.CbValidate.url = jQuery.CbValidate.validator.extend({ 72 valid : function(widget) { 73 return (widget.value() ? 74 widget.value().match(/^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/\S*)?$/i) 75 : true); 76 } 77}); 78 79/** 80 * makes sure a field has the same content as other fields in the same group 81 */ 82jQuery.CbValidate.equals = jQuery.CbValidate.nonempty.extend({ 83 84 /** 85 * constructor 86 * @param widget the Widget to attach to 87 * @param group the group this validator belongs to. If undefined 0 is assumed 88 */ 89 constructor : function(widget, group) { 90 var static_self = jQuery.CbValidate.equals; 91 if (group === undefined) group = 0; 92 this.base(widget); 93 this.widget = widget; 94 95 if (static_self.groups[group] === undefined) { 96 static_self.groups[group] = []; 97 } 98 99 this.group = static_self.groups[group]; 100 this.group.push(this); 101 }, 102 103 valid : function(widget) { 104 if (!this.base(widget)) return false; 105 var ret = true; 106 jQuery.each(this.group, function(i, group_widget) { 107 if (group_widget.widget.value() !== widget.value()) { 108 ret = false;
109 return false; 110 } else { 111 return true; 112 } 113 }); 114 return ret; 115 }, 116 117 destroy : function() { 118 for (var index in this.group) { 119 if (this.group[index] === this) { 120 this.group.splice(index, 1); 121 } 122 } 123 this.base(); 124 } 125}, { 126 groups : {} 127}); 128 129/** 130 * make sure the field contains a number or is empty 131 */ 132jQuery.CbValidate.numberOptional = jQuery.CbValidate.validator.extend({ 133 valid : function(widget) { 134 return this.base(widget) && (widget.value() ? widget.value().match(/\d*/) : true); 135 } 136}); 137 138/** 139 * make sure the field contains a number 140 */ 141jQuery.CbValidate.number = jQuery.CbValidate.nonempty.extend({ 142 valid : function(widget) { 143 return this.base(widget) && widget.value().match(/\d*/); 144 } 145}); 146 147/** 148 * make sure the field contains a phone number in E.123 standard format or is empty. 149 * http://de.wikipedia.org/wiki/E.123#Internationale_Rufnummern 150 */ 151jQuery.CbValidate.phoneNumberOptional = jQuery.CbValidate.validator.extend({ 152 valid : function(widget) { 153 return this.base(widget) && ( 154 widget.value() === '' 155 || widget.value() === jQuery.CbWidgetRegistry.bricks[widget.texts.text] 156 || widget.value().match(/^\+\d{1,3}\s\d+\s\d+$/) 157 ); 158 } 159}); 160 161/** 162 * make sure the field contains a phone number in E.164 standard format 163 * https://en.wikipedia.org/wiki/E.164 164 */ 165jQuery.CbValidate.phoneNumber = jQuery.CbValidate.nonempty.extend({ 166 valid : function(widget) { 167 return this.base(widget) && widget.value().match(/^\+\d{1,3}\s\d+\s\d+$/); 168 } 169}); 170 171jQuery.CbValidate.editingFinished = jQuery.CbValidate.validator.extend({ 172 valid : function(widget) {return widget.editingFinished();} 173}); 174 175jQuery.CbValidate.inputLength = jQuery.CbValidate.validator.extend({ 176 constructor : function(widget, min, max) { 177 this.base(widget); 178 this.min = (typeof(min) === 'undefined') ? jQuery.CbValidate.inputLength.default_min : min; 179 this.max = (typeof(max) === 'undefined') ? jQuery.CbValidate.inputLength.default_max : max; 180 }, 181 182 valid : function(widget) { 183 var length = widget.value().length; 184 return this.base(widget) && length >= this.min && length <= this.max; 185 } 186}, { 187 default_min : 5, 188 default_max : 255 189}); 190 191jQuery.CbValidate.pwStrength = jQuery.CbValidate.validator.extend({ 192 valid : function(widget) { 193 return this.base(widget) 194 && widget.value().length >= 8 195 && widget.value().match(/[a-zA-Z]+/) 196 && widget.value().match(/[0-9]+/) 197 && widget.value().match(/[\W]+/); 198 } 199}); 200 201jQuery.CbValidate.isChecked = jQuery.CbValidate.validator.extend({ 202 valid : function(widget) { 203 var name = jQuery(widget.element()).attr('name'); 204 return this.base(widget) && jQuery('input[name="'+name+'"]:checked').length > 0; 205 } 206}); 207 208jQuery.CbValidate.date = jQuery.CbValidate.validator.extend({ 209 valid : function(widget) { 210 return (widget.value() ? 211 widget.value().match(/^\d{2}([.\/-])\d{2}\1\d{4}$/) 212 : true); 213 } 214}); 215 216jQuery.CbValidate.time = jQuery.CbValidate.validator.extend({ 217 valid : function(widget) { 218 return (widget.value() ? 219 widget.value().match(/^\d{1,2}:\d{2}$/) 220 : true); 221 } 222}); 223
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.