-
Notifications
You must be signed in to change notification settings - Fork 0
/
password_regex.html
78 lines (59 loc) · 2.54 KB
/
password_regex.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
<!DOCTYPE html>
<html>
<body>
<style>
.valid_class{
color: #8AC007;
padding: 10px 10px ;
}
.error_class{
color: red;
padding: 10px 10px ;
}
</style>
<div> <h2> Jquery sample</h2></div>
<!-- jquery sample --->
<form>
Enter password : <input type="text" name="password" id="mypass" ><br>
<label id="error_msg"></label><br>
<input type="button" value="Submit">
</form>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$('#mypass').on('keyup', function() {
password = $(this).val();
var reg = /^(((.*\d.*[A-Z].*[!@#$%^&*? ~].*))|(.*[A-Z].*\d.*[!@#$%^&*? ~].*)|(.*[!@#$%^&*? ~].*[A-Z].*\d.*)|(.*[!@#$%^&*? ~].*\d.*[A-Z].*))$/;
if (reg.test(password)) {
$('#error_msg').html("<span class=\"valid_class\">valid password</span>");
}
else {
$('#error_msg').html("<span class=\"error_class\">password must contain at least one number,one capital letter and one special character</span>");
}
});
});
</script>
<!-- javascript function sample --->
<div> <h2> Javascript function sample</h2></div>
<script>
function validatePassword(password)
{
// patter to match : Atleast one number ,one capital letter, one special charector
var reg = /^(((.*\d.*[A-Z].*[!@#$%^&*? ~].*))|(.*[A-Z].*\d.*[!@#$%^&*? ~].*)|(.*[!@#$%^&*? ~].*[A-Z].*\d.*)|(.*[!@#$%^&*? ~].*\d.*[A-Z].*))$/;
if (reg.test(password)) {
//return true;
document.getElementById("error_msg2").innerHTML="<span class=\"valid_class\">valid password</span>";
}
else {
// return false;
document.getElementById("error_msg2").innerHTML="<span class=\"error_class\">password must contain at least one number,one capital letter and one special character</span> ";
}
}
</script>
<form>
Enter password : <input type="text" name="password" onkeyup="validatePassword(this.value)" ><br>
<label id="error_msg2"></label><br>
<input type="button" value="Submit">
</form>
</body>
</html>