-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidator.html
More file actions
139 lines (126 loc) · 4.87 KB
/
validator.html
File metadata and controls
139 lines (126 loc) · 4.87 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<script
src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.18.0/jquery.validate.min.js"></script>
</head>
<body class="container">
<h2>HTML Forms</h2>
<!-- <form action="" id="form">
First name:<br>
<input type="text" name="firstname" value="">
<br>
Last name:<br>
<input type="text" name="lastname" value="">
<br><br>
Password:<br>
<input type="password" name="password" value="" id="pass">
<br><br>
Confirm Password:<br>
<input type="password" name="cpassword" value="">
<br><br>
<input type="submit" value="Submit">
</form> -->
<form id="form">
<div class="form-group row">
<label for="inputPassword" class="col-sm-2 col-form-label">First Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="firstname" id="firstname" placeholder="Firstname">
</div>
</div>
<div class="form-group row">
<label for="inputPassword" class="col-sm-2 col-form-label">Last Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="lastname" id="lastname" placeholder="Lastname">
</div>
</div>
<div class="form-group row">
<label for="inputPassword" class="col-sm-2 col-form-label">Email</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="email" id="email" placeholder="Email address">
</div>
</div>
<div class="form-group row">
<label for="inputPassword" class="col-sm-2 col-form-label">Password</label>
<div class="col-sm-10">
<input type="password" class="form-control" name="password" id="password" placeholder="Password" minlength="6" maxlength="18" pattern="[A-Za-Z0-9]">
</div>
</div>
<div class="form-group row">
<label for="cpassword" class="col-sm-2 col-form-label">Confirm Password</label>
<div class="col-sm-10">
<input type="password" class="form-control" name="cpassword" id="cpassword" placeholder="Confirm Password">
</div>
</div>
<input type="submit" class="btn btn-primary" value="Submit">
</form>
<p>This is a validation done using jquery plugin. Which enhance your development speed.</p>
<!-- form validation using jQuery Validator plugin -->
<script>
// any additional function must have 3 arguments demo('functionName',function_defination,'error_msg')
$(document).ready(function(){
$.validator.addMethod('strongPassword', function(value,element){
return value.length >= 6 && /\d/.test(value) && /[a-z]/i.test(value) && /[A-Z]/.test(value);
},"Password must contain one small letter, one capital letter and one digit")
jQuery.validator.setDefaults({
highlight: function(element) {
jQuery(element).closest('.form-group').addClass('has-error');
},
unhighlight: function(element) {
jQuery(element).closest('.form-group').removeClass('has-error');
},
//errorElement: 'span',
errorClass: 'label label-danger',
errorPlacement: function(error, element) {
if(element.parent('.input-group').length) {
error.insertAfter(element.parent());
} else {
error.insertAfter(element);
}
}
});
$("#form").validate({
rules: {
// The key name on the left side is the name attribute
// of an input field. Validation rules are defined
// on the right side
firstname: "required",
lastname: "required",
email:{
required:true,
email: true
},
password:{
required: true,
strongPassword: true,
maxlength: 18
},
cpassword:{
required: true,
equalTo: "#password"
}
},
messages: {
firstname:{
required: "Please enter firstname",
},
lastname:{
required: "Please enter lastname",
},
email:{
required: "Please enter email address",
},
password:{
required: "Please enter password",
}
}
});
});
</script>
</body>
</html>