-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
228 lines (218 loc) · 10.2 KB
/
index.html
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<!DOCTYPE html>
<html lang="en" mode="ios" style="height:100%;min-height:100%;margin:0;padding:0;">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>JS Vanilla Validator</title>
<style>
input {
display: block;
border: none;
width: 100%;
color: #111111;
padding: 10px;
border-bottom: 1px solid #CCCCCC;
}
input[type=radio],
input[type=checkbox] {
display: inline-block;
width: auto;
}
</style>
</head>
<body style="height:100%;min-height:100%;margin:0;padding:0;">
<main style="height:100%;min-height: 100%;text-align: center;background-color: #FFFFFF;">
<div style="display:inline-block;width:600px;text-align: left;border-radius:20px;padding-bottom: 100px;">
<img src="img/header.png" alt="Box Sample" title="Box Sample" style="width:100%;max-width:100%;border-radius:5px">
<br>
<h1>JS Vanilla Validator </h1>
<p>
Hello there!
<br>
This JS Validator already saved me a lot of time in front end validation.
<br>
Although simple to make, front end validation usually takes time and is very repetitive.
<br>
If you're
building a multi language website or application, you can easily put more time just to
localize each string, text or phrase in the validation.
<br>
Pretty sure a language file will help a lot.
</p>
<h2>The goal</h2>
<p>
The goal for this script is to make easy to install/configure and fully customizable, Material UI-like box,
with more simple and beautifull alerts instead of the browser in-built one or load a
whole library/framework, with capacity to put callbacks using just a text string or, if
you prefer, using JS.
</p>
<p>
It already has:
<ul>
<li>Phone validation</li>
<li>Email validation</li>
<li>Website validation</li>
<li>Radio validation</li>
<li>Checkbox validation, be it only one checked or multiple</li>
<li>Text string validation</li>
<li>CPF validation</li>
<li>CNPJ validation</li>
<li>CEP validation</li>
<li>Security key validation - with image (uses cookies)</li>
</ul>
</p>
<p>
If something is not being matched, the script will notify right after the SUBMIT, and
PREVENT IT to be sent. Event will be triggered only if all conditions are met (form is
valid).
<br>
I hope it helps you, and that you enjoy using it!
<br>
This project repository is on: <a href="https://github.com/Matheus2212/js-validation-notification"
target="_bank">Project</a>
</p>
<hr>
<br>
<h2>Sample form</h2>
<form action="" data-validate="ok" data-callback="false, callback" data-title="My Sample Form">
<input type="text" name="field" placeholder="Text" data-required="Please fill the input here">
<br><br>
<input type="text" name="telefone" placeholder="Phone"
data-required-phone="Please inform the Phone || Phone is invalid">
<br><br>
<input type="text" name="email" placeholder="Email"
data-required-email="Please inform the Email || Email is invalid">
<br><br>
<input type="text" name="cpf" placeholder="CPF" data-required-cpf="Please inform the CPF || CPF is invalid">
<br><br>
<input type="text" name="cnpj" placeholder="CNPJ"
data-required-cnpj="Please inform the CNPJ || CNPJ is invalid">
<br>
<br>
<input type="text" name="cep" placeholder="CEP" data-required-cep="Please inform the CEP || CEP is invalid">
<br><br>
<label for="">
<input type="radio" data-required="Please, check the Radio button" name="radio">
Radio 1
</label>
<label for="">
<input type="radio" data-required="Please, check the Radio button" name="radio">
Radio 2
</label>
<label for="">
<input type="radio" data-required="Please, check the Radio button" name="radio">
Radio 3
</label>
<br><br>
<label for="">
<input type="checkbox" data-required="Please, check the Checkbox button" name="checkbox" data-minimum="2">
Check 1
</label>
<label for="">
<input type="checkbox" data-required="Please, check the Checkbox button" name="checkbox" data-minimum="2">
Check 2
</label>
<label for="">
<input type="checkbox" data-required="Please, check the Checkbox button" name="checkbox" data-minimum="2">
Check 3
</label>
<br><br>
<input type="text" placeholder="Password" name="password"
data-required-password="Please, inform the Password || The Password is too weak">
<br><br>
<input type="text" placeholder="URL" name="url"
data-required-url="Please, inform the URL || The URL is not Valid">
<br><br>
<div id="securityKeyWrapper">
<div id="securityKey"></div>
</div>
<button type="button" onclick="Validation.securityKey('securityKey','renew');">New
key</button>
<script>
setTimeout(function () {
Validation.securityKey("securityKey");
}, 300);
</script>
<input type="text" placeholder="Security Key" name="securityKey"
data-required-securitykey="Please, inform the security Key || The security key is invalid">
<br><br>
<button>Send</button>
</form>
<br /><br />
<hr />
<pre style="max-width: 100%;overflow:auto;background-color: #e5e5e5; border:2px solid #cccccc">
<code>
<h2>Sample form</h2>
<form action="" data-validate="ok" data-callback="false, callback" data-title="My Sample Form">
<input type="text" name="field" placeholder="Text" data-required="Please fill the input here">
<br><br>
<input type="text" name="telefone" placeholder="Phone"
data-required-phone="Please inform the Phone || Phone is invalid">
<br><br>
<input type="text" name="email" placeholder="Email"
data-required-email="Please inform the Email || Email is invalid">
<br><br>
<input type="text" name="cpf" placeholder="CPF" data-required-cpf="Please inform the CPF || CPF is invalid">
<br><br>
<input type="text" name="cnpj" placeholder="CNPJ"
data-required-cnpj="Please inform the CNPJ || CNPJ is invalid">
<br>
<br>
<input type="text" name="cep" placeholder="CEP" data-required-cep="Please inform the CEP || CEP is invalid">
<br><br>
<label for="">
<input type="radio" data-required="Please, check the Radio button" name="radio">
Radio 1
</label>
<label for="">
<input type="radio" data-required="Please, check the Radio button" name="radio">
Radio 2
</label>
<label for="">
<input type="radio" data-required="Please, check the Radio button" name="radio">
Radio 3
</label>
<br><br>
<label for="">
<input type="checkbox" data-required="Please, check the Checkbox button" name="checkbox" data-minimum="2">
Check 1
</label>
<label for="">
<input type="checkbox" data-required="Please, check the Checkbox button" name="checkbox" data-minimum="2">
Check 2
</label>
<label for="">
<input type="checkbox" data-required="Please, check the Checkbox button" name="checkbox" data-minimum="2">
Check 3
</label>
<br><br>
<input type="text" placeholder="Password" name="password"
data-required-password="Please, inform the Password || The Password is too weak">
<br><br>
<input type="text" placeholder="URL" name="url"
data-required-url="Please, inform the URL || The URL is not Valid">
<br><br>
<div id="securityKeyWrapper">
<div id="securityKey"></div>
</div>
<button type="button" onclick="Validation.securityKey('securityKey','renew');">New
key</button>
<script>
setTimeout(function () {
Validation.securityKey("securityKey");
}, 300);
</script>
<input type="text" placeholder="Security Key" name="securityKey"
data-required-securitykey="Please, inform the security Key || The security key is invalid">
<br><br>
<button>Send</button>
</form>
</code>
</pre>
</div>
</main>
<link rel="stylesheet" href="validation.style.css">
<script src="validation.functions.js" onload="Validation.init()"></script>
</body>
</html>