This repository has been archived by the owner on Oct 23, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
validation.dev.js
119 lines (99 loc) · 3.75 KB
/
validation.dev.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//---------------------------------------------------------------------------------
// Dado Validators, Copyright 2013 roydukkey.
// Dual licensed under the MIT (http://www.roydukkey.com/mit) and
// GPL Version 2 (http://www.roydukkey.com/gpl) licenses.
//---------------------------------------------------------------------------------
function ValidatorGetValue(id) {
var control = document.getElementById(id);
if (typeof(control.value) == "string") {
if ("type" in control && control.type == "file") return control.value.replace(/^.*[\\\/]/, '')
return control.value;
}
return ValidatorGetValueRecursive(control);
}
function ValidatorUpdateDisplay(val) {
if (val.display == "None") return;
val.style.visibility = val.style.display = "";
val.className = val.className.replace(val.invalidClassName, "").replace(/^\s+|\s+$/g, "");
if (
!val.isvalid || ( navigator.userAgent.indexOf("Mac") > -1 && navigator.userAgent.indexOf("MSIE") > -1 )
)
val.className += (val.className ? " " : "") + val.invalidClassName;
}
function RegularExpressionValidatorEvaluateIsValid(val) {
var value = ValidatorGetValue(val.controltovalidate);
if (ValidatorTrim(value).length == 0)
return true;
var rx = new RegExp(val.validationexpression, val.expressionoptions);
var matches = rx.exec(value);
return (matches != null && value == matches[0]);
}
function LengthValidatorEvaluateIsValid(val) { var min = ~~val.minimumlength, max = ~~val.maximumlength;
// Do not validate empty control. Use a required field validator.
if (ValidatorGetValue(val.controltovalidate) != "" && (max <= 0 && min > 0 || min <= max)) {
// See if value is greater than MinimumLength
if (min > 0 && ValidatorGetValue(val.controltovalidate).length < min) {
val.innerHTML = "<span>" + val.minimumerrormessage + "</span>";
return false;
}
// See if value is greater than MaximumLength
if (max > 0 && ValidatorGetValue(val.controltovalidate).length > max) {
val.innerHTML = "<span>" + val.maximumerrormessage + "</span>";
return false;
}
}
return true;
}
function TypeValidatorEvaluateIsValid(val) { var v = ValidatorGetValue(val.controltovalidate);
if(v == null) return true;
switch (val.type) {
case "Boolean":
return (v.toLowerCase() == "true" || v.toLowerCase() == "false");
case "Byte":
return +v >= 0 && +v <= 255;
case "Char":
return v.length == 1;
case "Decimal":
v = v.replace(",", "");
return +v >= -79228162514264337593543950335 && +v <= 79228162514264337593543950335;
case "Double":
v = v.replace(",", "");
return +v >= -1.7976931348623157E+308 && +v <= 1.7976931348623157E+308;
case "Int16":
return +v >= -32768 && +v <= 32767;
case "Int64":
return +v >= -9223372036854775808 && +v <= 9223372036854775807;
case "SByte":
return +v >= -128 && +v <= 127;
case "Single":
return +v >= -3.402823e38 && +v <= 3.402823e38;
//case "Int32":
default:
return +v >= -2147483648 && +v <= 2147483647;
}
}
function RequiredFieldValidatorEvaluateIsValid(val) {
// Validate for Checkbox
if(val.validatefor === "checkbox") {
return document.getElementById(val.controltovalidate).checked
}
// Validate for CheckboxList
else if(val.validatefor === "checkboxlist") {
var list = document.getElementById(val.controltovalidate)
, inputs = list.getElementsByTagName("input")
, i = 0;
for (; i < inputs.length;)
if (inputs[i++].checked)
return true;
return false;
}
// Default provided validation
else {
return ValidatorTrim(ValidatorGetValue(val.controltovalidate)) != ValidatorTrim(val.initialvalue);
}
}
function ValidateOnLoad() {
Page_InvalidControlToBeFocused = null;
if (typeof(OnLoad_Validators) == "undefined") return true;
for (var i = 0; i < OnLoad_Validators.length; i++) ValidatorValidate(OnLoad_Validators[i]);
}