-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.html
More file actions
121 lines (109 loc) · 3.39 KB
/
test.html
File metadata and controls
121 lines (109 loc) · 3.39 KB
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
120
121
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>HTML 5 complete</title>
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
article, aside, dialog, figure, footer, header,
hgroup, menu, nav, section { display: block; }
</style>
</head>
<body>
<h1>Js-validator test</h1>
<h2>Content</h2>
<p> execute this codes </p>
<pre>
<code>
(function() {
var results = [],
result_div = document.getElementById('ResultSpace'),
test = (function() {
var times = 1;
return function(test, result) {
if (test !== result) {
results.push('Failure @ ' + times);
} else {
results.push('Success @ ' + times);
}
times++;
}
}()),
display = function() {
var i = 0, html = '';
html += '<ul>';
for (i in results) {
html += '<li>' + results[i] + '</li>';
}
html += '</ul>';
result_div.innerHTML = html;
},
validator = jsValidator(), // create validator object
int_val = 1, // Integer
str_val = 'hogehoge', // String
date_val = '2011-05-01 12:13:16', // DateTime
ip_str = '192.168.11.1', // ip address
email = 'hogehoge@example.com'; // email
test(validator.exec(int_val, ['notempty']), true); // true
test(validator.exec(int_val, ['numeric']), true); // true
test(validator.exec(int_val, ['numeric', ['between', 3, 5]]), false); // false, because int_val equals 1 < 3
test(validator.exec(str_val, ['notempty', 'numeric']), false); // false, because the type of str_val is not integer.
test(validator.exec(str_val, [['strlength', 6]]), false); // false, because str_val is longer than 6 character.
test(validator.exec(date_val, ['datetime']), true); // true
test(validator.exec(ip_str, ['ip_addr']), true); // true
test(validator.exec(email, ['email']), true); // true
display();
}());
</code>
</pre>
<h2>Result</h2>
<div id="ResultSpace"></div>
<script src="src/js-validator.js"></script>
<script>
//<![CDATA[
/** validator test */
(function() {
var results = [],
result_div = document.getElementById('ResultSpace'),
test = (function() {
var times = 1;
return function(test, result) {
if (test !== result) {
results.push('Failure @ ' + times);
} else {
results.push('Success @ ' + times);
}
times++;
}
}()),
display = function() {
var i = 0, html = '';
html += '<ul>';
for (i in results) {
html += '<li>' + results[i] + '</li>';
}
html += '</ul>';
result_div.innerHTML = html;
},
validator = jsValidator(), // create validator object
int_val = 1, // Integer
str_val = 'hogehoge', // String
date_val = '2011-05-01 12:13:16', // DateTime
ip_str = '192.168.11.1', // ip address
email = 'hogehoge@example.com'; // email
test(validator.exec(int_val, ['notempty']), true); // true
test(validator.exec(int_val, ['numeric']), true); // true
test(validator.exec(int_val, ['numeric', ['between', 3, 5]]), false); // false, because int_val equals 1 < 3
test(validator.exec(str_val, ['notempty', 'numeric']), false); // false, because the type of str_val is not integer.
test(validator.exec(str_val, [['strlength', 6]]), false); // false, because str_val is longer than 6 character.
test(validator.exec(date_val, ['datetime']), true); // true
test(validator.exec(ip_str, ['ip_addr']), true); // true
test(validator.exec(email, ['email']), true); // true
display();
}());
//]]>
</script>
</body>
</html>