root/trunk/templates/html/js/validate.js @ 1

Revision 1, 3.1 KB (checked in by bradley, 5 years ago)

Initial import

Line 
1
2function validateInet(inputField, fieldDesc)
3{
4    var value = $F(inputField);
5    if (!value)
6    {
7        return; // Its not populated...
8    }
9    var quad1; var quad2; var quad3; var quad4;
10    var isValid = 1;
11    if (value.match(/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/))
12    {
13        quad1 = parseInt($1);
14        quad2 = parseInt($2);
15        quad3 = parseInt($3);
16        quad4 = parseInt($4);
17        if (quad1 >= 255 || quad2 >= 255 || quad3 >= 255 || quad4 >= 255)
18        {
19            isValid = 0;
20        }
21    }
22    else
23    {
24        isValid = 0;
25    }
26    if (isValid == 0)
27    {
28        alert(fieldDesc + ': \'' + value + '\' is not a valid IP address');
29        inputField.value = '';
30    }
31    return;
32}
33
34function validateBigInt(inputField, fieldDesc)
35{
36    var value = $F(inputField);
37    var num;
38    try {
39        if (isNaN(value))
40        {
41            throw('NaN');
42        }
43        num = parseInt(value);
44    }
45    catch(e)
46    {
47        alert(fieldDesc + ': \'' + value + '\' is not a valid number');
48        inputField.value = '';
49    }
50    if (num < -9223372036854775808 || num > 9223372036854775807)
51    {
52        alert(fieldDesc+ ': \'' + value + '\' is not between the ranges -9223372036854775808 to 9223372036854775807');
53        inputField.value = '';
54    }
55    return;
56}
57
58function validateInteger(inputField, fieldDesc)
59{
60    var value = $F(inputField);
61    var num;
62    try {
63        if (isNaN(value))
64        {
65            throw('NaN');
66        }
67        num = parseInt(value);
68    }
69    catch(e)
70    {
71        alert(fieldDesc + ': \'' + value + '\' is not a valid number');
72        inputField.value = '';
73    }
74    if (num < -2147483648 || num > 2147483647)
75    {
76        alert(fieldDesc + ': \'' + value + '\' is not between the ranges -2147483648 to 2147483647');
77        inputField.value = '';
78    }
79    return;
80}
81
82function validateSmallInt(inputField, fieldDesc)
83{
84    var value = $F(inputField);
85    var num;
86    try {
87        if (isNaN(value))
88        {
89            throw('NaN');
90        }
91        num = parseInt(value);
92    }
93    catch(e)
94    {
95        alert(fieldDesc + ': \'' + value + '\' is not a valid number');
96        inputField.value = '';
97    }
98    if (num < -32768 || num > 32767)
99    {
100        alert(fieldDesc + ': \'' + value + '\' is not between the ranges -32768 to 32767');
101        inputField.value = '';
102    }
103    return;
104}
105
106function validateDate(inputField, fieldDesc)
107{
108    var value = $F(inputField);
109    if (!value)
110    {
111        return;
112    }
113    var dd; var mm; var yyyy;
114    if (value.match(/^(\d\d\d\d)(\/|\-)(\d+)(\/|\-)(\d+)$/))
115    {
116        yyyy = parseInt($1);
117        mm = parseInt($3);
118        dd = parseInt($5);
119    }
120    else
121    {
122        alert(fieldDesc + ': \'' + value + '\' is not a valid date (YYYY-MM-DD)');
123        inputField.value = '';
124        return;
125    }
126    try {
127        date = new Date(yyyy, mm - 1, dd);
128        if (mm > 12 || dd > 31)
129        {
130            throw('OutOfRange');
131        }
132    }
133    catch(e)
134    {
135        alert(fieldDesc + ': \'' + value + '\' is not a valid date (YYYY-MM-DD)');
136        inputField.value = '';
137        return;
138    }
139    return;
140}
141
Note: See TracBrowser for help on using the browser.