This repository has been archived by the owner on Sep 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
index.html
629 lines (584 loc) · 29 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="UTF-8">
<!-- CSS only -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">
<title>HTML 5 & Bootstrap Jquery Form Validation Plugin</title>
</head>
<body>
<div class="container">
<div class="row mt-5 justify-content-center">
<div class="col-md-8">
<h1>HTML 5 & Bootstrap Jquery Form Validation Plugin</h1>
<div class="bg-light my-5 p-3">
<h3>HTML 5 & Bootstrap 5 & Jquery 3</h3>
<h5><a href="https://github.com/emretulek/jbvalidator">GITHUB</a></h5>
<ul>
<li><b>Html 5 validation</b></li>
<li><b>data-v-equal</b>: id of the element that should be the same</li>
<li><b>data-v-min-select</b>: multiple selectbox, minimum selectable count</li>
<li><b>data-v-max-select</b>: multiple selectbox, maximum selectable count</li>
<li><b>data-checkbox-group</b>: the parent attribute of group checkbox elements
<ol><b>data-v-min-select</b>: parent attribute minimum selectable count</ol>
<ol><b>data-v-required</b>: parent attribute required</ol>
</li>
<li><b>data-v-min</b>: alternative of the min attribute, this can be used for attribute type text
</li>
<li><b>data-v-max</b>: alternative of the max attribute, this can be used for attribute type text
</li>
<li><b>data-v-min-length</b>: alternative of the minlength attribute</li>
<li><b>data-v-max-length</b>: alternative of the maxlength attribute</li>
<li><b>data-v-min-size</b>: the input type file minimum file size (byte)</li>
<li><b>data-v-max-size</b>: the input type file maximum file size (byte)</li>
<li><b>data-v-message</b>: alternative error mesage</li>
</ul>
</div>
<div class="bg-light my-5 p-3">
<h3>Methods</h3>
<ul>
<li><b>validator</b>: add new custom validation</li>
<li><b>checkAll(formSelector = null, event = null)</b>: show errors without submitting the form, return error count</li>
<li><b>errorTrigger(inputSelector, message)</b>: show the error messages returned from the server.</li>
<li><b>reload()</b>: reload instance after dynamic element is added</li>
</ul>
</div>
<div class="bg-light my-5 p-3">
<h3>Usage</h3>
<code>
<pre>
<script src="dist/jbvalidator.min.js"></script>
<script>
$(function (){
let validator = $('form.needs-validation').jbvalidator({
errorMessage: true,
successClass: true,
language: "https://emretulek.github.io/jbvalidator/dist/lang/en.json"
});
//custom validate methode
validator.validator.custom = function(el, event){
if($(el).is('[name=password]') && $(el).val().length < 5){
return 'Your password is too weak.';
}
}
validator.validator.example = function(el, event){
if($(el).is('[name=username]') && $(el).val().length < 3){
return 'Your username is too short.';
}
}
//check form without submit
validator.checkAll(); //return error count
//reload instance after dynamic element is added
validator.reload();
})
</script>
</pre>
</code>
</div>
<div class="col-md-12">
<h3>Serverside validation</h3>
<p>You can show the error messages returned from the server. The ".errorTrigger" method can be used for
this.</p>
<p>.errorTrigger(element, message)</p>
<div class="bg-light my-5 p-3">
<code>
<pre>
<script src="dist/jbvalidator.min.js"></script>
<script>
$(function (){
let validatorServerSide = $('form.validatorServerSide').jbvalidator({
errorMessage: true,
successClass: false,
});
//serverside
$(document).on('submit', '.validatorServerSide', function(){
$.ajax({
method:"get",
url:"http://jsvalidation.test/test.json",
data: $(this).serialize(),
success: function (data){
if(data.status === 'error') {
validatorServerSide.errorTrigger($('[name=username]'), data.message);
}
}
})
return false;
});
})
</script>
</pre>
</code>
</div>
</div>
<div class="bg-light my-5 p-3">
<h3>Options</h3>
<code><pre>
{
language: '', //json file url
errorMessage: true,
successClass: false,
html5BrowserDefault: false,
validFeedBackClass: 'valid-feedback',
invalidFeedBackClass: 'invalid-feedback',
validClass: 'is-valid',
invalidClass: 'is-invalid'
}
</pre>
</code>
</div>
<div class="bg-light my-5 p-3">
<h3>Language file content</h3>
<code></code>
<code><pre>
{
"maxValue": "Value must be less than or equal to %s.",
"minValue": "Value must be greater than or equal to %s.",
"maxLength": "Please lengthen this text to %s characters or less (you are currently using %s characters).",
"minLength": "Please lengthen this text to %s characters or more (you are currently using %s characters).",
"minSelectOption": "Please select at least %s options.",
"maxSelectOption": "Please select at most %s options.",
"groupCheckBox": "Please select at least %s options.",
"equal": "This field does not match with %s field.",
"fileMinSize": "File size cannot be less than %s bytes.",
"fileMaxSize": "File size cannot be more than %s bytes.",
"number": "Please enter a number.",
"HTML5": {
"valueMissing": {
"INPUT": {
"default": "Please fill out this field.",
"checkbox": "Please check this box.",
"radio": "Please select one of these options.",
"file": "Please select a file."
},
"SELECT": "Please select an item in the list."
},
"typeMismatch": {
"email": "Please enter an e-mail address.",
"url": "Please enter a URL."
},
"rangeUnderflow": {
"date": "Value must be %s or later.",
"month": "Value must be %s or later.",
"week": "Value must be %s or later.",
"time": "Value must be %s or later.",
"datetimeLocale": "Value must be %s or later.",
"number": "Value must be greater than or equal to %s.",
"range": "Value must be greater than or equal to %s."
},
"rangeOverflow": {
"date": "Value must be %s or earlier.",
"month": "Value must be %s or earlier.",
"week": "Value must be %s or earlier.",
"time": "Value must be %s or earlier.",
"datetimeLocale": "Value must be %s or earlier.",
"number": "Value must be less than or equal to %s.",
"range": "Value must be less than or equal to %s."
},
"stepMismatch": {
"date": "You can only select every %s. day in the date calendar.",
"month": "You can only select every %s. month in the date calendar.",
"week": "You can only select every %s. week in the date calendar.",
"time": "You can only select every %s. second in the time picker.",
"datetimeLocale": "You can only select every %s. second in the time picker.",
"number": "Please enter a valid value. Only %s and a multiple of %s.",
"range": "Please enter a valid value. Only %s and a multiple of %s."
},
"tooLong": "Please lengthen this text to %s characters or less (you are currently using %s characters).",
"tooShort": "Please lengthen this text to %s characters or more (you are currently using %s characters).",
"patternMismatch": "Please match the request format. %s",
"badInput": {
"number": "Please enter a number."
}
}
}
</pre>
</code>
</div>
<form class="needs-validation row g-3" novalidate>
<div class="col-12 bg-light">
<div class="p-2">
The form's attribute have to novalidate
<code>
<form novalidate>
</code>
</div>
</div>
<div class="col-12 bg-light">
<div class="p-2">
<label>Email address</label>
<input type="email" class="form-control" placeholder="name@example.com" required>
</div>
<div class="py-2">
<code>
<input type="email" class="form-control" placeholder="name@example.com"
required>
</code>
</div>
</div>
<div class="col-12 bg-light">
<div class="p-2">
<label for="password">Password</label>
<input type="password" name="password" class="form-control" id="password" title="password" required>
</div>
<div class="py-2">
<code>
<input type="password" class="form-control" id="password"
title="password" required>
</code>
<ul>
<li><b>title:</b> filed name</li>
<li><b>id:</b> equal input selector</li>
</ul>
</div>
</div>
<div class="col-12 bg-light">
<div class="p-2">
<label for="password">equal - rePassword</label>
<input name="repassword" type="password" class="form-control" data-v-equal="#password" required>
</div>
<div class="p-2">
<code>
<input name="repassword" type="password" class="form-control"
data-v-equal="#password" required>
</code>
<ul>
<li><b>data-v-equal:</b> id of the element that should be the same</li>
</ul>
</div>
</div>
<div class="col-12 bg-light">
<div class="p-2">
<label>Example select</label>
<select class="form-select" required>
<option value="">Choose</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
</div>
<div class="p-2">
<code>
<select class="form-select" required>
</select>
</code>
</div>
</div>
<div class="col-12 bg-light">
<div class="p-2">
<label>Multiple select, minimum and maximumum selectable</label>
<select class="form-select" multiple data-v-min-select="2" data-v-max-select="3">
<option selected>Open this select menu</option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
<option value="4">Four</option>
<option value="5">Five</option>
</select>
</div>
<div class="p-2">
<code>
<select class="form-select" multiple data-v-min-select="2"
data-v-max-select="3">
</code>
<ul>
<li><b>multiple:</b> multiple select</li>
<li><b>data-v-min-select:</b> minimum selectable count</li>
<li><b>data-v-max-select:</b> maximum selectable count</li>
</ul>
</div>
</div>
<div class="col-12 bg-light">
<div class="p-2">
<label>Example textarea</label>
<textarea class="form-control" minlength="10" maxlength="165" required></textarea>
</div>
<div class="p-2">
<code>
<textarea class="form-control" minlength="10" maxlength="165"></textarea>
</code>
</div>
</div>
<div class="col-12 bg-light">
<div class="col-12 p-2" data-checkbox-group data-v-min-select="2" data-v-required>
<h3>Checkbox group minimum selectable</h3>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="defaultCheck1">
<label class="form-check-label" for="defaultCheck1">
checkbox 1
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="defaultCheck2">
<label class="form-check-label" for="defaultCheck2">
checkbox 2
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="defaultCheck3">
<label class="form-check-label" for="defaultCheck3">
checkbox 3
</label>
</div>
</div>
<div class="p-2">
<code>
<div data-checkbox-group data-v-min-select="2" data-v-required>
</div>
</code>
<ul>
<li>You have to create a parent element. The attributes apply to this parent.</li>
<li><b>data-checkbox-group</b>: parent attribute</li>
<li><b>data-v-min-select</b>: parent attribute, minimum selectable</li>
<li><b>data-v-required</b>: parent attribute, is required</li>
</ul>
</div>
</div>
<div class="col-12 bg-light">
<div class="p-2">
<label>URL</label>
<input type="url" class="form-control" placeholder="http://www" required>
</div>
<div class="p-2">
<code>
<input type="url" class="form-control" placeholder="http://www"
required>
</code>
</div>
</div>
<div class="col-12 bg-light">
<div class="p-2">
<label>Color</label>
<input type="color" name="color" class="form-control" required>
</div>
<div class="p-2">
<code>
<input type="color" name="color" class="form-control"
required>
</code>
</div>
</div>
<div class="col-12 bg-light">
<div class="p-2">
<label>Regex</label>
<input type="text" class="form-control" pattern="[0-9]+" title="Only number." required>
</div>
<div class="p-2">
<code>
<input type="text" class="form-control" pattern="[0-9]+"
title="Only number." required>
</code>
</div>
</div>
<div class="col-12 bg-light">
<div class="p-2">
<label>number - min - max</label>
<input type="number" class="form-control" min="10" max="100" required>
</div>
<div class="p-2">
<code>
<input type="number" class="form-control" min="10" max="100"
required>
</code>
</div>
</div>
<div class="col-12 bg-light">
<div class="p-2">
<label>custom - min - max</label>
<input type="text" class="form-control" data-v-min="10" data-v-max="100">
</div>
<div class="p-2">
<code>
<input type="text" class="form-control" data-v-min="10"
data-v-max="100">
</code>
<ul>
<li><b>data-v-min</b>: custom minimum number</li>
<li><b>data-v-max</b>: custom maximum number</li>
</ul>
</div>
</div>
<div class="col-12 bg-light">
<div class="p-2">
<label>custom min length - max length</label>
<input type="text" class="form-control" data-v-min-length="5" data-v-max-length="10">
</div>
<div class="p-2">
<code>
<input type="text" class="form-control" data-v-min-length="5"
data-v-max-length="10">
</code>
<ul>
<li><b>data-v-min-length</b>: custom minimum length</li>
<li><b>data-v-max-length</b>: custom maximum length</li>
</ul>
</div>
</div>
<div class="col-12 bg-light">
<div class="p-2">
<label>file</label>
<input type="file" class="form-control" data-v-min-size="400" data-v-max-size="450" multiple required>
</div>
<div class="p-2">
<code>
<input type="file" class="form-control" data-v-min-size="400"
data-v-max-size="450">
</code>
<ul>
<li><b>data-v-min-size</b>: custom minimum file size (byte)</li>
<li><b>data-v-max-size</b>: custom maximum file size (byte)</li>
</ul>
</div>
</div>
<div class="col-12 bg-light">
<div class="p-2">
<label>date</label>
<input type="date" class="form-control" min="2020-10-20">
</div>
<div class="p-2">
<code>
<input type="date" class="form-control" min="2020-10-20">
</code>
</div>
</div>
<div class="col-12 bg-light">
<div class="p-2">
<label>Custom message</label>
<input type="text" class="form-control" minlength="10" data-v-message="Please enter minimum 10 characters" required>
</div>
<div class="p-2">
<code>
<input type="text" class="form-control" minlength="10"
data-v-message="Please enter minimum 10 characters" required>
</code>
<ul>
<li><b>data-v-message</b>: This attribute allows you to change the original error message.
</li>
</ul>
</div>
</div>
<div class="col-12 bg-light">
<h3 class="p-2">Floating labels</h3>
<div class="p-2">
<div class="form-floating mb-3">
<input type="email" class="form-control" id="floatingInput" placeholder="name@example.com" required>
<label for="floatingInput">Email address</label>
</div>
<div class="form-floating">
<input type="password" class="form-control" id="floatingPassword" placeholder="Password" minlength="8" required>
<label for="floatingPassword">Password</label>
</div>
</div>
<div class="col-12 bg-light">
<div class="p-2">
<div class="form-floating">
<select class="form-select" id="floatingSelect" aria-label="Floating label select example" required>
<option selected value="">Open this select menu</option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
<label for="floatingSelect">Works with selects</label>
<div class="valid-feedback">Success feedback text</div>
</div>
</div>
</div>
<div class="p-2">
<code>
<pre>
<div class="form-floating mb-3">
<input type="email" class="form-control" id="floatingInput" placeholder="name@example.com">
<label for="floatingInput">Email address</label>
</div>
<div class="form-floating">
<input type="password" class="form-control" id="floatingPassword" placeholder="Password" minlength="8">
<label for="floatingPassword">Password</label>
</div>
<div class="form-floating">
<select class="form-select" id="floatingSelect" aria-label="Floating label select example" required>
<option selected value="">Open this select menu</option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
<label for="floatingSelect">Works with selects</label>
<div class="valid-feedback">Success feedback text</div>
</div>
</pre>
</code>
</div>
</div>
<div class="col-12">
<input type="submit" class="btn btn-primary" value="Submit">
</div>
</form>
</div>
</div>
<div class="row my-5 justify-content-center">
<div class="col-md-8">
<form class="validatorServerSide row g-3" novalidate>
<div class="col-12 bg-light">
<div class="p-2">
<div class="form-floating mb-3">
<input type="text" name="username" class="form-control" placeholder="username" required>
<label class="form-label">Username</label>
</div>
</div>
<div class="p-2">
<code>
<input type="text" name="username" class="form-control"
required>
</code>
</div>
</div>
<div class="col-12">
<input type="submit" class="btn btn-success" value="Submit to the server">
</div>
</form>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.min.js" crossorigin="anonymous"></script>
<!-- JavaScript Bundle with Popper.js -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-JEW9xMcG8R+pH31jmWH6WWP0WintQrMb4s7ZOdauHnUtxwoG2vI5DkLtS3qm9Ekf" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/@emretulek/jbvalidator"></script>
<script>
$(function () {
let validator = $('form.needs-validation').jbvalidator({
errorMessage: true,
successClass: true,
language: 'dist/lang/en.json'
});
//new custom validate methode
validator.validator.custom = function (el, event) {
if ($(el).is('[name=password]') && $(el).val().length < 5) {
return 'Your password is too weak.';
}
return '';
}
let validatorServerSide = $('form.validatorServerSide').jbvalidator({
errorMessage: true,
successClass: true,
});
//serverside
$(document).on('submit', '.validatorServerSide', function () {
$.ajax({
method: "get",
url: "test.json",
data: $(this).serialize(),
success: function (data) {
if (data.status === 'error') {
validatorServerSide.errorTrigger($('[name=username]'), data.message);
}
}
})
return false;
});
})
</script>
</body>
</html>