624 lines
28 KiB
JavaScript
624 lines
28 KiB
JavaScript
function isMissing(obj) {
|
|
return null == obj || "undefined" == typeof obj || !jQuery.isValidString(obj);
|
|
}
|
|
|
|
function InputValidator(validateTag, displayElementId, autoInit) {
|
|
this.validateTag = validateTag ? validateTag : InputValidator.ValidateTag, this.displayControl = document.getElementById(displayElementId),
|
|
this.inputs = new Array(), autoInit && this.init();
|
|
}
|
|
|
|
function _setNewInputGroup(validateTag, displayElementId) {
|
|
this.validateTag = validateTag, exists(displayElementId) && (this.displayControl = document.getElementById(displayElementId)),
|
|
this.init();
|
|
}
|
|
|
|
function _getInputs() {
|
|
return this.inputs;
|
|
}
|
|
|
|
function _getInput(id) {
|
|
for (var i = 0; i < this.inputs.length; i++) if (this.inputs[i].element.id == id) return this.inputs[i];
|
|
return !1;
|
|
}
|
|
|
|
function _getFirstInvalidInput() {
|
|
for (var i = 0; i < this.inputs.length; i++) if (!this.inputs[i].hasValidInput()) return this.inputs[i].element;
|
|
return null;
|
|
}
|
|
|
|
function _autoFocus() {
|
|
var elem = this.getFirstInvalidInput();
|
|
if (elem) try {
|
|
elem.focus(), elem.select();
|
|
} catch (err) {}
|
|
}
|
|
|
|
function _removeInput(id, useHTML) {
|
|
for (var i = 0; i < this.inputs.length; i++) this.inputs[i].element.id == id && (this.displayControl ? (this.inputs.splice(i, 1),
|
|
this.updateMessages(useHTML)) : (this.inputs[i].hideMessages(), this.inputs.splice(i, 1)));
|
|
}
|
|
|
|
function _init() {
|
|
var elems = document.getElementsByTagName("*");
|
|
this.inputs = new Array();
|
|
for (var i = 0; i < elems.length; i++) if ("true" == elems[i].getAttribute(this.validateTag)) {
|
|
var newInput = new ValidatedInput(elems[i]);
|
|
newInput.init(), this.inputs[this.inputs.length] = newInput;
|
|
}
|
|
}
|
|
|
|
function _attachKeyListeners(callback) {
|
|
for (var i = 0; i < this.inputs.length; i++) this.inputs[i].element.attachEvent ? this.inputs[i].element.attachEvent("onkeyup", callback) : this.inputs[i].element.onkeyup = callback;
|
|
}
|
|
|
|
function _allInputsValidate() {
|
|
for (var i = 0; i < this.inputs.length; i++) if (!this.inputs[i].hasValidInput()) return !1;
|
|
return !0;
|
|
}
|
|
|
|
function _allInputsAreClean() {
|
|
for (var i = 0; i < this.inputs.length; i++) if (!this.inputs[i].isClean()) return !1;
|
|
return !0;
|
|
}
|
|
|
|
function _singleInputValidates(id) {
|
|
for (var i = 0; i < this.inputs.length; i++) if (this.inputs[i].element.id == id) return this.inputs[i].hasValidInput();
|
|
return !1;
|
|
}
|
|
|
|
function _updateMessages(useHTML) {
|
|
var i;
|
|
if (this.displayControl) {
|
|
if (iLOGlobal.features.alt_mode_en) {
|
|
var errMsg = this.getRulesBroken(useHTML);
|
|
$(this.displayControl).displayError(errMsg);
|
|
} else $(this.displayControl).displayError({
|
|
text: this.getRulesBroken(useHTML)
|
|
});
|
|
this.displayControl.style.display = "block";
|
|
} else for (i = 0; i < this.inputs.length; i++) this.inputs[i].hasValidInput() ? this.inputs[i].hideMessages() : this.inputs[i].showMessages(useHTML);
|
|
}
|
|
|
|
function _updateFirstMessage(useHTML) {
|
|
this.clearMessages(), this.displayControl && (this.displayControl.innerHTML = this.getFirstRuleBroken(useHTML),
|
|
this.displayControl.style.display = "block");
|
|
}
|
|
|
|
function _clearMessages() {
|
|
if (this.displayControl) this.displayControl.innerHTML = "", this.displayControl.style.display = "none"; else for (var i = 0; i < this.inputs.length; i++) this.inputs[i].hideMessages();
|
|
}
|
|
|
|
function _getFirstRuleBroken(useHTML) {
|
|
for (var i = 0; i < this.inputs.length; i++) if (0 == this.inputs[i].hasValidInput()) return this.inputs[i].getRulesBroken(useHTML);
|
|
return !1;
|
|
}
|
|
|
|
function _getFirstRuleBrokenType() {
|
|
for (var i = 0; i < this.inputs.length; i++) if (0 == this.inputs[i].hasValidInput()) return this.inputs[i].getFirstRuleBrokenType();
|
|
return -1;
|
|
}
|
|
|
|
function _getAllRulesBroken(useHTML) {
|
|
for (var errors = "", i = 0; i < this.inputs.length; i++) 0 == this.inputs[i].hasValidInput() && (errors += this.inputs[i].getRulesBroken(useHTML));
|
|
return errors;
|
|
}
|
|
|
|
function ValidatedInput(elem) {
|
|
this.element = "undefined" == elem.tagName ? null : elem, this.cleanValue = this.element.value,
|
|
this.formIdentifier = "", this.linkedErrorLabel = null, this.invalidList = null,
|
|
this.regExp = null, this.fieldName = "", this.optional = !1, this.optionElement = null,
|
|
this.useCustomMessage = !1, this.rules = new Array(), this.relatives = new Array(),
|
|
this.relativeNames = new Array(), this.range = new Object(), this.range.min = null,
|
|
this.range.max = null, this.errorFormatFunction = null, this.validationFunction = null;
|
|
}
|
|
|
|
function _initInput() {
|
|
var names = null, msg = "";
|
|
try {
|
|
var captionElemId = this.element.getAttribute(InputValidator.CaptionTag);
|
|
if (captionElemId) {
|
|
var fieldCaption = document.getElementById(captionElemId).innerHTML;
|
|
jQuery.isValidString(fieldCaption) ? -1 != fieldCaption.indexOf(":") ? this.fieldName = fieldCaption.split(":")[0] : this.fieldName = fieldCaption : this.captionElement = null;
|
|
}
|
|
if (this.element.getAttribute(InputValidator.FormIdTag) && (this.formIdentifier = " " + this.element.getAttribute(InputValidator.FormIdTag)),
|
|
this.element.getAttribute(InputValidator.OptionTag) && (this.optionElement = document.getElementById(this.element.getAttribute(InputValidator.OptionTag))),
|
|
this.element.getAttribute(InputValidator.RelativesTag)) {
|
|
names = this.element.getAttribute(InputValidator.RelativesTag), names = names.split(";");
|
|
for (var i = 0; i < names.length; i++) this.relatives[this.relatives.length] = document.getElementById(names[i]);
|
|
}
|
|
if (this.element.getAttribute(InputValidator.RelatedCaptionTag)) {
|
|
names = this.element.getAttribute(InputValidator.RelatedCaptionTag), names = names.split(";");
|
|
for (var n = 0; n < names.length; n++) this.relativeNames[this.relativeNames.length] = getLabelText(names[n]);
|
|
}
|
|
if (this.element.getAttribute(InputValidator.InvalidTag) && (this.invalidList = this.element.getAttribute(InputValidator.InvalidTag)),
|
|
this.element.getAttribute(InputValidator.RegExpTag) && (this.regExp = new RegExp(this.element.getAttribute(InputValidator.RegExpTag))),
|
|
this.element.getAttribute(InputValidator.RangeTag)) {
|
|
var range = this.element.getAttribute(InputValidator.RangeTag);
|
|
range = range.split(";"), range.length >= 2 && (range[0] = parseInt(range[0], 10),
|
|
range[1] = parseInt(range[1], 10), this.range.min = range[0] < range[1] ? range[0] : range[1],
|
|
this.range.max = range[0] > range[1] ? range[0] : range[1]);
|
|
}
|
|
if (null != this.element.getAttribute(InputValidator.CustomTag) && (this.validationFunction = eval(this.element.getAttribute(InputValidator.CustomTag))),
|
|
null != this.element.getAttribute(InputValidator.RulesTag)) {
|
|
var rules = this.element.getAttribute(InputValidator.RulesTag);
|
|
rules = rules.split(";");
|
|
for (var j = 0; j < rules.length; j++) null != this.element.getAttribute(InputValidator.MessageTag) ? 0 == this.useCustomMessage && (msg = this.getInputString(this.element.getAttribute(InputValidator.MessageTag)),
|
|
this.useCustomMessage = !0) : msg = this.getInputString(this.getStringKey(rules[j])),
|
|
rules[j] == ValidationRule.Optional ? this.optional = !0 : this.addRule(rules[j], msg);
|
|
} else this.addRule(ValidationRule.Required, this.getInputString(this.getStringKey(ValidationRule.Required)));
|
|
if (null != this.element.getAttribute(InputValidator.LabelTag)) {
|
|
var labelElement = document.getElementById(this.element.getAttribute(InputValidator.LabelTag));
|
|
labelElement && (this.linkedErrorLabel = labelElement, this.errorFormatFunction = _errorFomatter);
|
|
}
|
|
} catch (e) {
|
|
alert("error in init: " + e.message);
|
|
}
|
|
}
|
|
|
|
function _getRule(type) {
|
|
for (var i = 0; i < this.rules.length; i++) if (this.rules[i].type == type) return this.rules[i];
|
|
return null;
|
|
}
|
|
|
|
function _addRule(type, msg) {
|
|
return isNaN(type) ? void 0 : this.rules.push(new ValidationRule(type, msg));
|
|
}
|
|
|
|
function _removeRule(type) {
|
|
if (!isNaN(type)) for (var i = 0; i < this.rules.length; i++) this.rules[i].type == type && (this.rules.splice(i, 1),
|
|
this.linkedErrorLabel && jQuery.isValidString(this.linkedErrorLabel.innerHTML) && this.showMessages());
|
|
}
|
|
|
|
function _isClean() {
|
|
return this.element.value == this.cleanValue;
|
|
}
|
|
|
|
function _hasValidInput() {
|
|
for (var i = 0; i < this.rules.length; i++) if (this.rules[i].isRuleBroken(this, this.relatives, this.range, this.optional)) return !1;
|
|
return !0;
|
|
}
|
|
|
|
function getFirstRuleBrokenType() {
|
|
for (var i = 0; i < this.rules.length; i++) if (this.rules[i].isRuleBroken(this, this.relatives, this.range, this.optional)) return this.rules[i].type;
|
|
return -1;
|
|
}
|
|
|
|
function _getRulesBroken(useHTML) {
|
|
var i, errMsg = "", lineBreak = useHTML ? "<br />" : "\n";
|
|
if (1 == this.useCustomMessage) {
|
|
for (i = 0; i < this.rules.length; i++) if (this.rules[i].isRuleBroken(this, this.relatives, this.range, this.optional)) {
|
|
errMsg = this.rules[i].msg + this.formIdentifier + lineBreak;
|
|
break;
|
|
}
|
|
} else for (i = 0; i < this.rules.length; i++) this.rules[i].isRuleBroken(this, this.relatives, this.range, this.optional) && (errMsg += this.rules[i].msg + this.formIdentifier + lineBreak);
|
|
return errMsg;
|
|
}
|
|
|
|
function _showMessages(useHTML) {
|
|
this.linkedErrorLabel && (this.linkedErrorLabel.innerHTML = this.getRulesBroken(useHTML),
|
|
this.errorFormatFunction && this.errorFormatFunction(this.element, !0));
|
|
}
|
|
|
|
function _hideMessages() {
|
|
this.linkedErrorLabel && (this.linkedErrorLabel.innerHTML = "", this.errorFormatFunction && this.errorFormatFunction(this.element, !1));
|
|
}
|
|
|
|
function _getInputString(type) {
|
|
var regexp = null;
|
|
if (jQuery.isValidString(type)) {
|
|
var localString = "unknown type: " + type, langKey = "inputValidator." + type;
|
|
switch (type) {
|
|
case "fieldInvalid":
|
|
localString = iLO.translateString(langKey, "{%1} is invalid.");
|
|
break;
|
|
|
|
case "fieldMatch":
|
|
localString = iLO.translateString(langKey, "{%1} Confirm must match {%1}.");
|
|
break;
|
|
|
|
case "fieldRequired":
|
|
localString = iLO.translateString(langKey, "{%1} is a required field.");
|
|
break;
|
|
|
|
case "fieldString":
|
|
localString = iLO.translateString(langKey, "{%1} must contain a text value.");
|
|
break;
|
|
|
|
case "fieldStringLength":
|
|
localString = iLO.translateString(langKey, "{%1} must contain exactly {%min} characters.");
|
|
break;
|
|
|
|
case "fieldStringRange":
|
|
localString = iLO.translateString(langKey, "{%1} must contain {%min} to {%max} characters.");
|
|
break;
|
|
|
|
case "fieldNumber":
|
|
localString = iLO.translateString(langKey, "{%1} must contain a numeric value.");
|
|
break;
|
|
|
|
case "fieldNumberRange":
|
|
localString = iLO.translateString(langKey, "{%1} must contain a numeric value between {%min} and {%max}.");
|
|
break;
|
|
|
|
case "fieldInteger":
|
|
localString = iLO.translateString(langKey, "{%1} must contain an integer.");
|
|
break;
|
|
|
|
case "fieldIntRange":
|
|
localString = iLO.translateString(langKey, "{%1} must contain an integer between {%min} and {%max}.");
|
|
break;
|
|
|
|
case "fieldEmail":
|
|
localString = iLO.translateString(langKey, "{%1} must contain a valid email address.");
|
|
break;
|
|
|
|
case "fieldDate":
|
|
localString = iLO.translateString(langKey, "{%1} must contain a valid date.");
|
|
break;
|
|
|
|
case "fieldIp":
|
|
localString = iLO.translateString(langKey, "{%1} must contain a valid IP address.");
|
|
break;
|
|
|
|
case "fieldIpv6":
|
|
localString = iLO.translateString(langKey, "{%1} must contain a valid IPv6 address.");
|
|
break;
|
|
|
|
case "fieldIpv6Prefix":
|
|
localString = iLO.translateString(langKey, "{%1} must contain a valid Prefix Length value.");
|
|
break;
|
|
|
|
case "fieldNoSpaces":
|
|
localString = iLO.translateString(langKey, "{%1} must not contain spaces.");
|
|
break;
|
|
|
|
case "fieldRegex":
|
|
localString = iLO.translateString(langKey, "{%1} must contain {%custom-string}");
|
|
break;
|
|
|
|
case "fieldChars":
|
|
localString = iLO.translateString(langKey, "{%1} must not contain any of these characters: {%char-list}");
|
|
break;
|
|
|
|
case "fieldUnique":
|
|
localString = iLO.translateString(langKey, "{%1} must be unique.");
|
|
break;
|
|
|
|
case "fieldDependent":
|
|
localString = iLO.translateString(langKey, "{%1} requires {%2} to be supplied first.");
|
|
break;
|
|
|
|
case "fieldIpOrHost":
|
|
localString = iLO.translateString(langKey, "{%1} must contain a valid IP address, hostname or FQDN.");
|
|
break;
|
|
|
|
case "fieldIpv4SubnetMask":
|
|
localString = iLO.translateString(langKey, "{%1} must contain a valid subnet mask.");
|
|
break;
|
|
|
|
default:
|
|
localString = iLO.translateString(type);
|
|
}
|
|
if (jQuery.isValidString(localString)) {
|
|
if (this.fieldName.length > 0 && (regexp = new RegExp("{%1}", "g"), localString = localString.replace(regexp, this.fieldName)),
|
|
this.relativeNames.length > 0) {
|
|
var names = "";
|
|
for (i = 0; i < this.relativeNames.length; i++) names += (i > 0 ? ", " : "") + this.relativeNames[i];
|
|
regexp = new RegExp("{%2}", "g"), localString = localString.replace(regexp, names);
|
|
}
|
|
if (0 != this.range.min && null == this.range.min || 0 != this.range.max && null == this.range.max || (regexp = new RegExp("{%min}", "g"),
|
|
localString = localString.replace(regexp, this.range.min), regexp = new RegExp("{%max}", "g"),
|
|
localString = localString.replace(regexp, this.range.max)), null != this.invalidList && "" != this.invalidList) {
|
|
var charList = "";
|
|
for (i = 0; i < this.invalidList.length; i++) charList += this.invalidList.charAt(i) + " ";
|
|
regexp = new RegExp("{%char-list}"), localString = localString.replace(regexp, charList);
|
|
}
|
|
if (this.element.getAttribute(InputValidator.MsgInsertTag)) {
|
|
var msg = this.element.getAttribute(InputValidator.MsgInsertTag);
|
|
regexp = new RegExp("{%custom-string}"), localString = localString.replace(regexp, iLO.translateString("inputValidator." + msg, msg));
|
|
}
|
|
}
|
|
return "" == localString ? "[not found]" : localString;
|
|
}
|
|
}
|
|
|
|
function _getStringKey(type) {
|
|
var szValue = "", useExKey = this.fieldName.length > 0;
|
|
switch (parseInt(type, 10)) {
|
|
case ValidationRule.IpAddress:
|
|
szValue = useExKey ? ValidatedInput.IpRequiredKeyEx : ValidatedInput.IpRequiredKey;
|
|
break;
|
|
|
|
case ValidationRule.Ipv6Address:
|
|
szValue = useExKey ? ValidatedInput.Ipv6RequiredKeyEx : ValidatedInput.Ipv6RequiredKey;
|
|
break;
|
|
|
|
case ValidationRule.Ipv6AddressPrefOp:
|
|
szValue = useExKey ? ValidatedInput.Ipv6PRequiredKeyEx : ValidatedInput.Ipv6PRequiredKey;
|
|
break;
|
|
|
|
case ValidationRule.EmailAddress:
|
|
szValue = useExKey ? ValidatedInput.EmailRequiredKeyEx : ValidatedInput.EmailRequiredKey;
|
|
break;
|
|
|
|
case ValidationRule.Number:
|
|
szValue = null != this.range.min && null != this.range.max ? useExKey ? ValidatedInput.NumberRangeKeyEx : ValidatedInput.NumberRangeKey : useExKey ? ValidatedInput.NumberRequiredKeyEx : ValidatedInput.NumberRequiredKey;
|
|
break;
|
|
|
|
case ValidationRule.Integer:
|
|
szValue = null != this.range.min && null != this.range.max ? useExKey ? ValidatedInput.IntegerRangeKeyEx : ValidatedInput.IntegerRangeKey : useExKey ? ValidatedInput.IntegerRequiredKeyEx : ValidatedInput.IntegerRequiredKey;
|
|
break;
|
|
|
|
case ValidationRule.String:
|
|
szValue = null != this.range.min && null != this.range.max ? this.range.min == this.range.max && useExKey ? ValidatedInput.StringLengthKeyEx : useExKey ? ValidatedInput.StringRangeKeyEx : ValidatedInput.StringRangeKey : useExKey ? ValidatedInput.StringRequiredKeyEx : ValidatedInput.StringRequiredKey;
|
|
break;
|
|
|
|
case ValidationRule.Date:
|
|
szValue = useExKey ? ValidatedInput.DateRequiredKeyEx : ValidatedInput.DateRequiredKey;
|
|
break;
|
|
|
|
case ValidationRule.Mirror:
|
|
szValue = useExKey ? ValidatedInput.InputMatchKeyEx : ValidatedInput.InputMatchKey;
|
|
break;
|
|
|
|
case ValidationRule.NoSpaces:
|
|
szValue = useExKey ? ValidatedInput.NoSpacesKeyEx : ValidatedInput.NoSpacesKey;
|
|
break;
|
|
|
|
case ValidationRule.RegExp:
|
|
szValue = useExKey ? ValidatedInput.RegexKeyEx : ValidatedInput.RegexKey;
|
|
break;
|
|
|
|
case ValidationRule.InvalidChars:
|
|
szValue = useExKey ? ValidatedInput.InvalidCharsKeyEx : ValidatedInput.InvalidCharsKey;
|
|
break;
|
|
|
|
case ValidationRule.Unique:
|
|
szValue = useExKey ? ValidatedInput.UniqueKeyEx : ValidatedInput.UniqueKey;
|
|
break;
|
|
|
|
case ValidationRule.Dependent:
|
|
szValue = useExKey ? ValidatedInput.DependentKeyEx : ValidatedInput.DependentKey;
|
|
break;
|
|
|
|
case ValidationRule.IpOrHost:
|
|
szValue = useExKey ? ValidatedInput.IpOrHostKeyEx : ValidatedInput.IpOrHostRequiredKey;
|
|
break;
|
|
|
|
case ValidationRule.Ipv4SubnetMask:
|
|
szValue = useExKey ? ValidatedInput.Ipv4SubnetMaskKeyEx : ValidatedInput.Ipv4SubnetMaskRequiredKey;
|
|
break;
|
|
|
|
case ValidationRule.Required:
|
|
default:
|
|
szValue = useExKey ? ValidatedInput.FieldRequiredKeyEx : ValidatedInput.FieldRequiredKey;
|
|
}
|
|
return szValue;
|
|
}
|
|
|
|
function ValidationRule(type, msg) {
|
|
this.type = isNumber(type) ? parseInt(type, 10) : null, this.msg = jQuery.isValidString(msg) ? msg : "";
|
|
}
|
|
|
|
function _isRuleBroken(validatedInput, obj, range, optional) {
|
|
var broken, i, elem = validatedInput.element, value = elem.value;
|
|
if (validatedInput.optionElement && 0 == validatedInput.optionElement.checked) return !1;
|
|
if (isMissing(value) && optional) return !1;
|
|
switch (this.type) {
|
|
case ValidationRule.Required:
|
|
broken = isMissing(value), null != range.min && 0 == range.min && (broken = !1);
|
|
break;
|
|
|
|
case ValidationRule.IpAddress:
|
|
broken = !isValidIPAddress(value), broken || optional || "0.0.0.0" != value.trim() || (broken = !0);
|
|
break;
|
|
|
|
case ValidationRule.Ipv6Address:
|
|
broken = !isValidIPv6Address(value);
|
|
break;
|
|
|
|
case ValidationRule.Ipv6AddressPrefOp:
|
|
broken = !isValidIPv6AddressPrefix(value);
|
|
break;
|
|
|
|
case ValidationRule.EmailAddress:
|
|
broken = !isEmailAddress(value);
|
|
break;
|
|
|
|
case ValidationRule.Date:
|
|
broken = !isDate(value);
|
|
break;
|
|
|
|
case ValidationRule.Number:
|
|
broken = !isNumber(value), broken || null == range.min || null == range.max || (broken = !(parseFloat(value) >= parseFloat(range.min) && parseFloat(value) <= parseFloat(range.max)));
|
|
break;
|
|
|
|
case ValidationRule.Integer:
|
|
broken = !isInteger(value), broken || null == range.min || null == range.max || (broken = !(parseInt(value, 10) >= parseInt(range.min, 10) && parseInt(value, 10) <= parseInt(range.max, 10)));
|
|
break;
|
|
|
|
case ValidationRule.String:
|
|
broken = !jQuery.isValidString(value) && 0 !== range.min, broken || null == range.min || null == range.max || (broken = !(value.length >= parseInt(range.min, 10) && value.length <= parseInt(range.max, 10)));
|
|
break;
|
|
|
|
case ValidationRule.Mirror:
|
|
if (Array.isArray(obj)) for (i = 0; i < obj.length; i++) if ((jQuery.isValidString(obj[i].value) || jQuery.isValidString(value) && "true" == obj[i].getAttribute("mirror-controlled")) && !valuesMatch(value, obj[i].value)) return !0;
|
|
broken = !1;
|
|
break;
|
|
|
|
case ValidationRule.NoSpaces:
|
|
broken = hasSpaces(value);
|
|
break;
|
|
|
|
case ValidationRule.RegExp:
|
|
broken = validatedInput.regExp.test(value);
|
|
break;
|
|
|
|
case ValidationRule.InvalidChars:
|
|
broken = containsChars(value, validatedInput.invalidList);
|
|
break;
|
|
|
|
case ValidationRule.Unique:
|
|
if (Array.isArray(obj)) for (i = 0; i < obj.length; i++) if (jQuery.isValidString(obj[i].value) && valuesMatch(value, obj[i].value)) return !0;
|
|
broken = !1;
|
|
break;
|
|
|
|
case ValidationRule.Dependent:
|
|
if (Array.isArray(obj)) for (i = 0; i < obj.length; i++) if (!jQuery.isValidString(obj[i].value) && jQuery.isValidString(value)) return !0;
|
|
broken = !1;
|
|
break;
|
|
|
|
case ValidationRule.IpOrHost:
|
|
broken = !isValidIpOrHost(value);
|
|
break;
|
|
|
|
case ValidationRule.Ipv4SubnetMask:
|
|
broken = !isValidIpv4SubnetMask(value);
|
|
break;
|
|
|
|
case ValidationRule.IpOrHostMultiTarget:
|
|
broken = !isValidIpOrHostMultiTarget(value);
|
|
break;
|
|
|
|
case ValidationRule.Custom:
|
|
broken = !validatedInput.validationFunction(value);
|
|
break;
|
|
|
|
default:
|
|
broken = !1;
|
|
}
|
|
return broken;
|
|
}
|
|
|
|
function getLabelText(id) {
|
|
var fieldCaption = document.getElementById(id).innerHTML;
|
|
return jQuery.isValidString(fieldCaption) ? -1 != fieldCaption.indexOf(":") ? fieldCaption.split(":")[0] : fieldCaption : id;
|
|
}
|
|
|
|
function valuesMatch(obj1, obj2) {
|
|
return isMissing(obj1) || isMissing(obj2) ? !1 : obj1 == obj2;
|
|
}
|
|
|
|
function containsChars(value, charList) {
|
|
for (var i = 0; i < charList.length; i++) {
|
|
var regExp = new RegExp(/[a-z0-9]/i), esc = regExp.test(charList.charAt(i)) ? "" : "\\";
|
|
if (regExp = new RegExp(esc + charList.charAt(i)), regExp.test(value)) return !0;
|
|
}
|
|
return !1;
|
|
}
|
|
|
|
function isEmailAddress(obj) {
|
|
if (jQuery.isValidString(obj) && obj.length <= 64) {
|
|
var regExpEmail = new RegExp(/^([\w\-\.\+\_])+@([a-zA-Z0-9]([\-a-zA-Z0-9])?)+((\.?)+([a-zA-Z0-9]([\-][a-zA-Z0-9])?))*$/);
|
|
if (regExpEmail.test(obj)) return !0;
|
|
}
|
|
return !1;
|
|
}
|
|
|
|
function isDate(obj) {
|
|
var aDate = new Date(obj);
|
|
return "NaN" != aDate.toDateString() && "Invalid Date" != aDate.toDateString();
|
|
}
|
|
|
|
function isNumber(obj) {
|
|
return null != obj && !isNaN(obj);
|
|
}
|
|
|
|
function isInteger(obj) {
|
|
return isNumber(obj) ? parseInt(obj, 10) == parseFloat(obj) : !1;
|
|
}
|
|
|
|
function hasSpaces(obj) {
|
|
if (jQuery.isValidString(obj)) for (var i = 0; i < obj.length; i++) if (" " == obj.charAt(i)) return !0;
|
|
return !1;
|
|
}
|
|
|
|
function fileSizeExceeded(filePath, maxBytes) {
|
|
try {
|
|
var fso = new ActiveXObject("Scripting.FileSystemObject"), img = new Image();
|
|
img.src = filePath;
|
|
var file = fso.GetFile(img.src);
|
|
if (file.Size > maxBytes) return !0;
|
|
} catch (err) {
|
|
return alert(err.message), "error";
|
|
}
|
|
return !1;
|
|
}
|
|
|
|
function isValidIpOrHost(obj) {
|
|
var i, tokens, invalid_chars = new RegExp(/(^-|-$|[\u0001-\u002c]|\u002e|\u002f|[\u003a-\u0040]|[\u005b-\u005e]|\u0060|[\u007b-\u007f])/);
|
|
if (isValidIPAddress(obj) || isValidIPv6Address(obj)) return !0;
|
|
if (obj.length > 255) return !1;
|
|
if (tokens = obj.split("."), tokens.length > 1) {
|
|
for (i = 0; i < tokens.length; i++) if (!jQuery.isValidString(tokens[i]) || tokens[i].length > 63 || invalid_chars.test(tokens[i])) return !1;
|
|
return !0;
|
|
}
|
|
return !1;
|
|
}
|
|
|
|
function isValidIpOrHostMultiTarget(obj) {
|
|
var i, n, targets, tokens, invalid_chars = new RegExp(/(^-|-$|[\u0001-\u001f]|[\u0021-\u002c]|\u002e|\u002f|[\u003c-\u0040]|[\u005b-\u005e]|\u0060|[\u007b-\u007f])/);
|
|
if (obj.length > 255) return !1;
|
|
for (targets = obj.split(";"), n = 0; n < targets.length; n++) if (!isValidIPAddress(targets[n].trim()) && !isValidIPv6Address(targets[n].trim())) for (tokens = targets[n].split("."),
|
|
i = 0; i < tokens.length; i++) if (!jQuery.isValidString(tokens[i].trim()) || tokens[i].length > 63 || invalid_chars.test(tokens[i])) return !1;
|
|
return !0;
|
|
}
|
|
|
|
function isValidIpv4SubnetMask(obj) {
|
|
var re = /^(255.255.255.(25[542]|24[80]|224|192|128|0)|255.255.(25[42]|24[80]|224|192|128|0).0|255.(25[42]|24[80]|224|192|128|0).0.0|(25[42]|24[80]|224|192|128|0).0.0.0)$/;
|
|
return re.test(obj);
|
|
}
|
|
|
|
function _errorFomatter(elem, isError) {
|
|
elem && (isError ? $(elem).closest("div.form-field").addClass("form-field--error") : $(elem).closest("div.form-field").removeClass("form-field--error"));
|
|
}
|
|
|
|
InputValidator.ValidateTag = "validate-me", InputValidator.LabelTag = "linked-error",
|
|
InputValidator.MessageTag = "msg-key", InputValidator.MsgInsertTag = "msg-insert-key",
|
|
InputValidator.RulesTag = "rule-list", InputValidator.CaptionTag = "caption-label",
|
|
InputValidator.RelativesTag = "related-inputs", InputValidator.RangeTag = "range",
|
|
InputValidator.InvalidTag = "invalid-list", InputValidator.RegExpTag = "reg-exp",
|
|
InputValidator.FormIdTag = "unique-id", InputValidator.RelatedCaptionTag = "related-labels",
|
|
InputValidator.OptionTag = "option-id", InputValidator.CustomTag = "custom-func",
|
|
ValidatedInput.InputInvalidKey = "inputInvalid", ValidatedInput.InputMatchKey = "inputMatch",
|
|
ValidatedInput.FieldRequiredKey = "inputRequired", ValidatedInput.NumberRequiredKey = "inputNumber",
|
|
ValidatedInput.NumberRangeKey = "inputNumberRange", ValidatedInput.IntegerRequiredKey = "inputInteger",
|
|
ValidatedInput.IntegerRangeKey = "inputIntegerRange", ValidatedInput.StringRequiredKey = "inputString",
|
|
ValidatedInput.StringRangeKey = "inputStringRange", ValidatedInput.DateRequiredKey = "inputDate",
|
|
ValidatedInput.EmailRequiredKey = "inputEmail", ValidatedInput.IpRequiredKey = "inputIp",
|
|
ValidatedInput.Ipv6RequiredKey = "inputIpv6", ValidatedInput.Ipv6PRequiredKey = "inputIpv6Prefix",
|
|
ValidatedInput.NoSpacesKey = "inputNoSpaces", ValidatedInput.InvalidCharsKey = "inputChars",
|
|
ValidatedInput.RegexKey = "inputRegex", ValidatedInput.UniqueKey = "inputUnique",
|
|
ValidatedInput.DependentKey = "inputDependent", ValidatedInput.IpOrHostRequiredKey = "inputIpOrHost",
|
|
ValidatedInput.Ipv4SubnetMaskRequiredKey = "inputIpv4SubnetMask", ValidatedInput.InputInvalidKeyEx = "fieldInvalid",
|
|
ValidatedInput.InputMatchKeyEx = "fieldMatch", ValidatedInput.FieldRequiredKeyEx = "fieldRequired",
|
|
ValidatedInput.NumberRequiredKeyEx = "fieldNumber", ValidatedInput.NumberRangeKeyEx = "fieldNumberRange",
|
|
ValidatedInput.IntegerRequiredKeyEx = "fieldInteger", ValidatedInput.IntegerRangeKeyEx = "fieldIntRange",
|
|
ValidatedInput.StringRequiredKeyEx = "fieldString", ValidatedInput.StringLengthKeyEx = "fieldStringLength",
|
|
ValidatedInput.StringRangeKeyEx = "fieldStringRange", ValidatedInput.DateRequiredKeyEx = "fieldDate",
|
|
ValidatedInput.EmailRequiredKeyEx = "fieldEmail", ValidatedInput.IpRequiredKeyEx = "fieldIp",
|
|
ValidatedInput.Ipv6RequiredKeyEx = "fieldIpv6", ValidatedInput.Ipv6PRequiredKeyEx = "fieldIpv6Prefix",
|
|
ValidatedInput.NoSpacesKeyEx = "fieldNoSpaces", ValidatedInput.InvalidCharsKeyEx = "fieldChars",
|
|
ValidatedInput.RegexKeyEx = "fieldRegex", ValidatedInput.IpOrHostKeyEx = "fieldIpOrHost",
|
|
ValidatedInput.Ipv4SubnetMaskKeyEx = "fieldIpv4SubnetMask", ValidationRule.Optional = 0,
|
|
ValidationRule.Required = 1, ValidationRule.IpAddress = 2, ValidationRule.EmailAddress = 3,
|
|
ValidationRule.Date = 4, ValidationRule.Number = 5, ValidationRule.String = 6, ValidationRule.Mirror = 7,
|
|
ValidationRule.NoSpaces = 8, ValidationRule.Integer = 9, ValidationRule.RegExp = 10,
|
|
ValidationRule.InvalidChars = 11, ValidationRule.Exclusive = 12, ValidationRule.Dependent = 13,
|
|
ValidationRule.Ipv6Address = 14, ValidationRule.Ipv6AddressPrefOp = 15, ValidationRule.Unique = 16,
|
|
ValidationRule.IpOrHost = 17, ValidationRule.Ipv4SubnetMask = 18, ValidationRule.IpOrHostMultiTarget = 19,
|
|
ValidationRule.Custom = 99, InputValidator.prototype.init = _init, InputValidator.prototype.attachKeyListeners = _attachKeyListeners,
|
|
InputValidator.prototype.setNewInputGroup = _setNewInputGroup, InputValidator.prototype.getInputs = _getInputs,
|
|
InputValidator.prototype.getInput = _getInput, InputValidator.prototype.getFirstInvalidInput = _getFirstInvalidInput,
|
|
InputValidator.prototype.getFirstRuleBrokenType = _getFirstRuleBrokenType, InputValidator.prototype.autoFocus = _autoFocus,
|
|
InputValidator.prototype.removeInput = _removeInput, InputValidator.prototype.allInputsValidate = _allInputsValidate,
|
|
InputValidator.prototype.allInputsAreClean = _allInputsAreClean, InputValidator.prototype.singleInputValidates = _singleInputValidates,
|
|
InputValidator.prototype.getFirstRuleBroken = _getFirstRuleBroken, InputValidator.prototype.getRulesBroken = _getAllRulesBroken,
|
|
InputValidator.prototype.updateMessages = _updateMessages, InputValidator.prototype.updateFirstMessage = _updateFirstMessage,
|
|
InputValidator.prototype.clearMessages = _clearMessages, ValidatedInput.prototype.init = _initInput,
|
|
ValidatedInput.prototype.addRule = _addRule, ValidatedInput.prototype.getRule = _getRule,
|
|
ValidatedInput.prototype.removeRule = _removeRule, ValidatedInput.prototype.isClean = _isClean,
|
|
ValidatedInput.prototype.hasValidInput = _hasValidInput, ValidatedInput.prototype.getFirstRuleBrokenType = getFirstRuleBrokenType,
|
|
ValidatedInput.prototype.getRulesBroken = _getRulesBroken, ValidatedInput.prototype.showMessages = _showMessages,
|
|
ValidatedInput.prototype.hideMessages = _hideMessages, ValidatedInput.prototype.getInputString = _getInputString,
|
|
ValidatedInput.prototype.getStringKey = _getStringKey, ValidationRule.prototype.isRuleBroken = _isRuleBroken; |