1<form class="needs-validation" novalidate>
2 <div class="form-row">
3 <div class="col-md-4 mb-3">
4 <label for="validationCustom01">First name</label>
5 <input type="text" class="form-control" id="validationCustom01" placeholder="First name" value="Mark" required>
6 <div class="valid-feedback">
7 Looks good!
8 </div>
9 </div>
10 <div class="col-md-4 mb-3">
11 <label for="validationCustom02">Last name</label>
12 <input type="text" class="form-control" id="validationCustom02" placeholder="Last name" value="Otto" required>
13 <div class="valid-feedback">
14 Looks good!
15 </div>
16 </div>
17 <div class="col-md-4 mb-3">
18 <label for="validationCustomUsername">Username</label>
19 <div class="input-group">
20 <div class="input-group-prepend">
21 <span class="input-group-text" id="inputGroupPrepend">@</span>
22 </div>
23 <input type="text" class="form-control" id="validationCustomUsername" placeholder="Username" aria-describedby="inputGroupPrepend" required>
24 <div class="invalid-feedback">
25 Please choose a username.
26 </div>
27 </div>
28 </div>
29 </div>
30 <div class="form-row">
31 <div class="col-md-6 mb-3">
32 <label for="validationCustom03">City</label>
33 <input type="text" class="form-control" id="validationCustom03" placeholder="City" required>
34 <div class="invalid-feedback">
35 Please provide a valid city.
36 </div>
37 </div>
38 <div class="col-md-3 mb-3">
39 <label for="validationCustom04">State</label>
40 <input type="text" class="form-control" id="validationCustom04" placeholder="State" required>
41 <div class="invalid-feedback">
42 Please provide a valid state.
43 </div>
44 </div>
45 <div class="col-md-3 mb-3">
46 <label for="validationCustom05">Zip</label>
47 <input type="text" class="form-control" id="validationCustom05" placeholder="Zip" required>
48 <div class="invalid-feedback">
49 Please provide a valid zip.
50 </div>
51 </div>
52 </div>
53 <div class="form-group">
54 <div class="form-check">
55 <input class="form-check-input" type="checkbox" value="" id="invalidCheck" required>
56 <label class="form-check-label" for="invalidCheck">
57 Agree to terms and conditions
58 </label>
59 <div class="invalid-feedback">
60 You must agree before submitting.
61 </div>
62 </div>
63 </div>
64 <button class="btn btn-primary" type="submit">Submit form</button>
65</form>
66
67<script>
68// Example starter JavaScript for disabling form submissions if there are invalid fields
69(function() {
70 'use strict';
71 window.addEventListener('load', function() {
72 // Fetch all the forms we want to apply custom Bootstrap validation styles to
73 var forms = document.getElementsByClassName('needs-validation');
74 // Loop over them and prevent submission
75 var validation = Array.prototype.filter.call(forms, function(form) {
76 form.addEventListener('submit', function(event) {
77 if (form.checkValidity() === false) {
78 event.preventDefault();
79 event.stopPropagation();
80 }
81 form.classList.add('was-validated');
82 }, false);
83 });
84 }, false);
85})();
86</script>
1<form>
2 <div class="form-row">
3 <div class="col-md-4 mb-3">
4 <label for="validationServer01">First name</label>
5 <input type="text" class="form-control is-valid" id="validationServer01" placeholder="First name" value="Mark" required>
6 <div class="valid-feedback">
7 Looks good!
8 </div>
9 </div>
10 <div class="col-md-4 mb-3">
11 <label for="validationServer02">Last name</label>
12 <input type="text" class="form-control is-valid" id="validationServer02" placeholder="Last name" value="Otto" required>
13 <div class="valid-feedback">
14 Looks good!
15 </div>
16 </div>
17 <div class="col-md-4 mb-3">
18 <label for="validationServerUsername">Username</label>
19 <div class="input-group">
20 <div class="input-group-prepend">
21 <span class="input-group-text" id="inputGroupPrepend3">@</span>
22 </div>
23 <input type="text" class="form-control is-invalid" id="validationServerUsername" placeholder="Username" aria-describedby="inputGroupPrepend3" required>
24 <div class="invalid-feedback">
25 Please choose a username.
26 </div>
27 </div>
28 </div>
29 </div>
30 <div class="form-row">
31 <div class="col-md-6 mb-3">
32 <label for="validationServer03">City</label>
33 <input type="text" class="form-control is-invalid" id="validationServer03" placeholder="City" required>
34 <div class="invalid-feedback">
35 Please provide a valid city.
36 </div>
37 </div>
38 <div class="col-md-3 mb-3">
39 <label for="validationServer04">State</label>
40 <input type="text" class="form-control is-invalid" id="validationServer04" placeholder="State" required>
41 <div class="invalid-feedback">
42 Please provide a valid state.
43 </div>
44 </div>
45 <div class="col-md-3 mb-3">
46 <label for="validationServer05">Zip</label>
47 <input type="text" class="form-control is-invalid" id="validationServer05" placeholder="Zip" required>
48 <div class="invalid-feedback">
49 Please provide a valid zip.
50 </div>
51 </div>
52 </div>
53 <div class="form-group">
54 <div class="form-check">
55 <input class="form-check-input is-invalid" type="checkbox" value="" id="invalidCheck3" required>
56 <label class="form-check-label" for="invalidCheck3">
57 Agree to terms and conditions
58 </label>
59 <div class="invalid-feedback">
60 You must agree before submitting.
61 </div>
62 </div>
63 </div>
64 <button class="btn btn-primary" type="submit">Submit form</button>
65</form>