-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
demo.html
632 lines (547 loc) · 18.3 KB
/
demo.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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
<!doctype html>
<html>
<title>OctaValidate Demo Page</title>
<head>
<meta name="author" content="Simon Ugorji">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description"
content="Octavalidate: This JavaScript Library helps to validate your HTML forms using validation rules, sophisticated regular expressions and form input attributes">
<meta name="title" content="Octavalidate Demo Page">
<meta property="og:description"
content="Octavalidate: This JavaScript Library helps to validate your HTML forms using validation rules, sophisticated regular expressions and form input attributes">
<meta property="og:title" content="Octavalidate Demo Page">
<link rel="icon" href="img/ov-image.png">
</head>
<style>
@import url("https://fonts.googleapis.com/css2?family=Roboto&display=swap");
* {
outline: none;
margin: 0px;
padding: 0px;
}
body {
font-family: 'Roboto', sans-serif !important;
margin: 0;
font-size: 1rem;
font-weight: 400;
line-height: 1.5;
color: #212529;
background-color: #fff;
-webkit-text-size-adjust: 100%;
-webkit-tap-highlight-color: transparent;
display: contents;
min-height: 100%;
}
label {
font-size: 1em;
display: block;
margin-bottom: 5px;
}
input {
margin: 0;
font-family: inherit;
font-size: inherit;
line-height: inherit;
}
h2 {
font-size: calc(1.325rem + .9vw);
}
h1,
h2,
h3,
h4,
h5,
h6 {
margin-top: 0;
margin-bottom: 0.5rem;
font-weight: 500;
line-height: 1.2;
}
input:not([type="file"]) {
display: block;
border-radius: 5px;
background-color: #e9e9e9 !important;
border: 2px solid #787878;
width: calc(100% - 24px);
padding: 10px;
}
.alert-danger {
color: #fff;
background-color: #ef2546;
}
.alert-success {
color: #fff;
background-color: #18b96a;
}
.notification {
padding: 20px;
}
.notification>p {
margin: 0px;
}
.notification.is-info {
border-left: .3em solid #1d72aa;
background-color: #eef6fc;
color: #1d72aa;
}
.text-left {
text-align: left;
}
.text-center {
text-align: center;
}
.reg-btn {
background-image: linear-gradient(120deg, #155799, #159957);
}
.block {
display: block !important;
width: 100%;
}
div.form-group {
margin: 10px 0 10px 0;
width: 100%;
}
button {
border: 2px solid #fff;
text-align: center;
padding: 15px;
border-radius: 10px;
color: #fff;
cursor: pointer;
}
hr {
border: 1px solid whitesmoke;
margin: 2em 0px 2em 0px;
}
.form-cont {
padding: var(--container-padding);
border: 1px solid #ddd;
border-radius: 5px;
max-width: var(--container-width);
}
input[type="checkbox"] {
width: initial;
display: initial;
margin-right: 5px;
height: initial;
}
small {
display: block;
margin: 5px 0;
font-size: .875em
}
.mt-10 {
margin-top: 10px;
}
.mb-10 {
margin-bottom: 10px;
}
.mt-0 {
margin-top: 0px !important;
}
.fw-bold {
font-weight: bold;
}
.p-100 {
padding: 10px;
}
.demo-bg-section {
height: 300px;
width: 100%;
position: absolute;
background-image: linear-gradient(120deg, #155799, #159957);
box-shadow: 0px 5px 14px 5px #95a6ae;
}
.form-section {
position: relative;
margin-top: 8rem;
}
.bg-white {
background-color: #fff !important;
}
.text-white {
color: #fff !important;
}
.social-btn {
letter-spacing: 1px;
display: block;
color: #fff;
font-size: 15px;
text-decoration: none;
text-transform: uppercase;
border: .125rem solid transparent;
padding: .75rem;
border-radius: .25rem;
-webkit-transition: color .15s ease-in-out, background-color .15s ease-in-out, border-color .15s ease-in-out, -webkit-box-shadow .15s ease-in-out;
transition: color .15s ease-in-out, background-color .15s ease-in-out, border-color .15s ease-in-out, -webkit-box-shadow .15s ease-in-out;
transition: color .15s ease-in-out, background-color .15s ease-in-out, border-color .15s ease-in-out, box-shadow .15s ease-in-out;
transition: color .15s ease-in-out, background-color .15s ease-in-out, border-color .15s ease-in-out, box-shadow .15s ease-in-out, -webkit-box-shadow .15s ease-in-out;
}
.bmc-btn {
height: 50px !important
}
.social-btn {
border: 1px solid #03A9F4;
color: #fff;
background-color: #03A9F4;
}
.social-btn:hover {
background-color: transparent;
border: 1px solid #03A9F4;
color: #03A9F4;
}
.mt-20 {
margin-top: 20px;
}
.mb-20 {
margin-bottom: 20px;
}
.mb-30 {
margin-bottom: 30px;
}
.ml-10 {
margin-left: 10px;
}
.ml-20 {
margin-left: 20px;
}
.mt-10 {
margin-top: 10px;
}
.p-20 {
padding: 20px;
}
.p-10 {
padding: 10px;
}
.list-inline,
.list-unstyled {
padding-left: 0;
list-style: none;
}
.list-inline-item {
display: inline-block;
}
.list-inline-item:not(:last-child) {
margin-right: .5rem;
}
@media screen and (max-width:520px) {
.list-inline-item {
display: block !important;
margin-bottom: 10px;
}
.list-inline-item:not(:last-child) {
margin-right: 0;
}
}
.footer {
padding: 20px;
background-color: #02151d;
}
.briefing {
background-color: #f6f6f6;
position: relative;
}
.brief-group {
padding-inline-start: 20px;
list-style-type: disclosure-closed;
}
.brief-group-inner {
padding-inline-start: 20px;
list-style-type: square;
}
.brief-item {
font-size: 1.1em;
color: #03A9F4;
}
.brief-item-inner {
font-size: 1em;
}
.p-5 {
padding: 5px;
}
.text-uppercase {
text-transform: uppercase;
}
.text-gray {
color: rgb(100, 100, 100);
}
/* The snackbar - position it at the bottom and in the middle of the screen */
/*
deleting a highlight saved less than 60 seconds ago shouldnt show highlight has been saved */
#alert_snackbar {
visibility: hidden;
/* Hidden by default. Visible on click */
min-width: 250px;
/* Set a default minimum width */
margin-left: -125px;
/* Divide value of min-width by 2 */
color: #fff;
/* White text color */
text-align: center;
/* Centered text */
border-radius: 2px;
/* Rounded borders */
position: fixed;
/* Sit on top of the screen */
z-index: 1;
/* Add a z-index if needed */
left: 50%;
/* Center the snackbar */
top: 10px;
/* 30px from the bottom */
height: 3rem;
display: inline-flex;
align-self: center;
justify-content: center;
flex-direction: column;
}
/* Show the snackbar when clicking on a button (class added with JavaScript) */
#alert_snackbar.show {
visibility: visible;
/* Show the snackbar */
/* Add animation: Take 0.5 seconds to fade in and out the snackbar.
However, delay the fade out process for 2.5 seconds */
-webkit-animation: fadein 0.5s, fadeout 0.5s 2.5s;
animation: fadein 0.5s, fadeout 0.5s 2.5s;
}
/* Animations to fade the snackbar in and out */
@-webkit-keyframes fadein {
from {
bottom: 0;
opacity: 0;
}
to {
bottom: 30px;
opacity: 1;
}
}
@keyframes fadein {
from {
bottom: 0;
opacity: 0;
}
to {
bottom: 30px;
opacity: 1;
}
}
@-webkit-keyframes fadeout {
from {
bottom: 30px;
opacity: 1;
}
to {
bottom: 0;
opacity: 0;
}
}
@keyframes fadeout {
from {
bottom: 30px;
opacity: 1;
}
to {
bottom: 0;
opacity: 0;
}
}
a.footer-link {
text-decoration: none;
color: rgb(24 163 221);
}
a.footer-link:hover {
color: #fff;
text-decoration: none;
}
.link {
color: inherit;
}
.brand-title {
margin: 10px;
font-size: 2em;
font-weight: bold;
color: #fff;
}
.d-block {
display: block !important;
}
:root {
--container-width: 370px;
--container-padding: 20px;
}
/***
I FIXED A LONG EXISTING BUG YAAAY!
You might not have noticed that this library had a bug with validating form inputs using the onchange handler.
length now needs to check if value exists before it works
removed successBorder entirely
Enjoying octavalidate? Please leave a short review on Openbase: https://openbase.com/js/octavalidate#rate
As a developer of this great library, I can assure you that this is the best form validation library.
In all my projects, I use octavalidate to validate form inputs both client-side and server-side, and the implementation process is quick.
In as much as there are inbuilt rules, the library allows you to add your custom regular expression if you wish to validate a value that must follow a particular pattern.
Try it out today!
***/
</style>
<script src="src/validate.js"></script>
<body id="octavalidate_demo_page">
<section class="demo-bg-section">
<div align="center" class="mt-20">
<img class="d-block" src="img/ov-success-white.png" width="50px">
<h4 class="brand-title">octaValidate</h4>
</div>
</section>
<div align="center" class="form-section">
<div class="text-left form-cont bg-white">
<form id="form_demo" novalidate>
<h2 class="text-center mt-0 text-uppercase">DEMO Form</h2>
<div class="notification is-info mt-20 mb-20">
<p>Try to break through 😎😎😎</p>
</div>
<div class="form-group">
<label>Username <span style="color:#ff0000">*</span></label>
<input type="text" id="inp_uname" octavalidate="R,USERNAME"
ov-required-msg="Your username is required" ov-username-msg="Please enter a valid username"
placeholder="Your username" length="5">
</div>
<div class="form-group">
<label>Email <span style="color:#ff0000">*</span></label>
<input type="text" ov-required-msg="Your Email Address is required" id="inp_reg_email"
octavalidate="R,EMAIL" placeholder="Your Email Address">
</div>
<div class="form-group">
<label>Password <span style="color:#ff0000">*</span></label>
<input type="password" id="inp_reg_pwd" octavalidate="R,PASS"
ov-required-msg="Your password is required" placeholder="Your Password">
</div>
<div class="form-group">
<label>Re-enter password</label>
<input type="password" id="inp_reg_pwd2" equalto="inp_reg_pwd"
ov-equalto-msg="Both passwords do not match" placeholder="Re-enter Password">
</div>
<div class="form-group">
<label>How many times do you eat in a day? <span style="color:#ff0000">*</span></label>
<input ov-range-msg="Please enter a value between 1 - 5" octavalidate="R" id="inp_range" range="1-5"
type="number" placeholder="5">
</div>
<div class="mt-100">
<input type="checkbox" id="inp_terms" octavalidate="R"
ov-required-msg="Please accept the terms and conditions">I accept the terms and conditions
</div>
<div class="form-group">
<button class="reg-btn block" type="submit">RUN TEST</button>
</div>
</form>
</div>
</div>
<div id="alert_snackbar" class="alert-danger">
Light attracts bugs!
</div>
</body>
<section class="briefing mt-20">
<div class="p-20">
<h2>On The Form</h2>
<ul class="mt-20 brief-group">
<li class="brief-item">Strict Mode is enabled</li>
</ul>
<ul class="mt-20 brief-group-inner">
<li class="brief-item-inner">Reserved Keywords</li>
</ul>
<p class="mt-10 ml-20">With <b>strict mode</b> enabled, users are not allowed to provide some <b>reserved
keywords</b> as values for form inputs. </p>
<p class="mt-10 ml-20">Aside from the default words, you are allowed to provide a custom set of words to check
against, <a class="link" href="https://octagon-simon.github.io/projects/octavalidate/config.html">please
refer to
the documentation.</a></p>
<div class="notification is-info mt-20 mb-20 mt-10 ml-20">
<p>Try to provide <b>null, NaN</b> or <b>undefined</b> as a value, then submit.</p>
</div>
<ul class="mt-20 brief-group-inner">
<li class="brief-item-inner">Input value is trimmed</li>
</ul>
<p class="mt-10 ml-20">With <b>strict mode</b> enabled, <b>extra white</b> space at the start and at the end of
an input value is removed.</p>
<ul class="mt-20 brief-group">
<li class="brief-item">callbacks are defined</li>
</ul>
<p class="mt-10 ml-20">With the callback feature, you can declare a function that will be invoked if validation
tests passes or fails, then pass it as an argument to the <b>validateCallBack()</b> method.
</p>
<p class="mt-10 ml-20"><a class="link"
href="https://octagon-simon.github.io/projects/octavalidate/api.html#callback">Learn
more about the callback method</a></p>
<ul class="mt-20 brief-group">
<li class="brief-item">validation status is returned</li>
</ul>
<p class="mt-10 ml-20">Invoke this method anytime to see the number of validation errors on the form.</p>
<div class="notification is-info mt-20 mb-20 mt-10 ml-20">
<p>With the callback and status methods, you can alert the user in <b>real time</b> of the number of
validation errors on the form.</p>
</div>
</div>
</section>
<footer class="footer">
<div class="text-center">
<h3 class="text-white mb-20">CONNECT WITH ME</h3>
<ul class="list-inline list-unstyled mb-30">
<li class="list-inline-item"><a href="https://twitter.com/ugorji_simon" target="_blank"
class="social-btn">Twitter</a></li>
<li class="list-inline-item">
<a href="https://www.linkedin.com/in/simon-ugorji-57a6a41a3" target="_blank"
class="social-btn">LinkedIn</a>
</li>
</ul>
</div>
<h3 class="text-white text-center"><a href="https://octagon-simon.github.io/projects/octavalidate/" target="_blank"
class="footer-link">
VISIT OUR DOCUMENTATION
</a></h3>
<div class="mt-20 mb-20 text-center">
<script type="text/javascript" src="https://cdnjs.buymeacoffee.com/1.0.0/button.prod.min.js"
data-name="bmc-button" data-slug="simon.ugorji" data-color="#40DCA5" data-emoji="" data-font="Cookie"
data-text="Buy me a coffee" data-outline-color="#000000" data-font-color="#ffffff"
data-coffee-color="#FFDD00"></script>
</div>
<p id="footer-ov-info" class="text-gray mt-20 text-center">Octavalidate @ 1.3.2 🚀 Since January 2022</p>
</footer>
</html>
<script>
//create instance of class null, NaN,undefined,admin,empty
let myForm = new octaValidate('form_demo', {
strictMode: true,
strictWords: ["null", "empty", "undefined", "NaN"]
});
document.querySelector('#footer-ov-info').innerHTML = `Octavalidate @ ${myForm.version()} 🚀 Since January 2022`;
//add custom rule
myForm.customRule("PASS", /^12345+$/, "Please enter 12345");
//define callback
myForm.validateCallBack(function () {
//success callback
showAlert('No Validation error', 'alert-success');
}, function () {
//error callback
showAlert(`${(Number(myForm.status()) > 1) ? myForm.status() + " validation errors" : myForm.status() + " validation error"}`, 'alert-danger');
});
/*Handle submission here*/
let formEl = document.querySelector('#form_demo');
formEl.addEventListener('submit', function (e) {
e.preventDefault();
//invoke the validate method
if (myForm.validate()) {
//return type == true - > validation successful
showAlert('No Validation error', 'alert-success');
//process form data here
} else {
//return type == false - > validation failed
showAlert(`${(Number(myForm.status()) > 1) ? myForm.status() + " validation errors" : myForm.status() + " validation error"}`, 'alert-danger');
}
})
//custom function to toggle alert snackbar
function showAlert(text = "Light Attracts Bugs!", addClass = "alert-danger") {
const p = document.querySelector("#alert_snackbar");
p.classList = "";
p.classList.add("show", addClass);
p.innerHTML = text;
// After 3 seconds, remove the show class from DIV
setTimeout(function () { p.classList.remove("show"); }, 3000);
}
</script>