-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
116 lines (104 loc) · 4.26 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Password Validation Check</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.2/css/all.min.css"
integrity="sha512-1sCRPdkRXhBV2PBLUdRb4tMg1w2YPf37qatUFeS7zlBy7jJI8Lf4VHwWfZZfpXtYSLy85pkm9GaYVYMfw5BC1A=="
crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="box">
<div class="box-img">
<img class="img-user" src="hacker.png" alt="hacker">
</div>
<div class="inputBox">
<input type="text" id="username" placeholder="Username" onkeyup="checkUsername(this.value)">
<input type="password" id="pswrd" placeholder="Password" onkeyup="checkPassword(this.value)">
<input type="submit" id="submit" value="Submit">
<span id="toggleBtn"></span>
</div>
<div class="validation">
<ul>
<li id="length-username">At least 5 characters username.</li>
<li id="lower">At least one lowercase character.</li>
<li id="upper">At least one uppercase character.</li>
<li id="number">At least one number.</li>
<li id="special">At least one special character.</li>
<li id="length">At least 8 characters password.</li>
</ul>
</div>
</div>
<script>
let userName = document.getElementById('username');
let lengthUserName = document.getElementById('length-username');
let pswrd = document.getElementById('pswrd');
let toggleBtn = document.getElementById('toggleBtn');
let lowerCase = document.getElementById('lower');
let upperCase = document.getElementById('upper');
let digit = document.getElementById('number');
let specialChar = document.getElementById('special');
let minLenght = document.getElementById('length');
function checkUsername(data) {
const length = new RegExp('(?=.{5,})');
//maximum length validation check
if (length.test(data)) {
lengthUserName.classList.add('valid');
} else {
lengthUserName.classList.remove('valid');
}
}
function checkPassword(data) {
//javascript regular expression pattern
const lower = new RegExp('(?=.*[a-z])');
const upper = new RegExp('(?=.*[A-Z])');
const number = new RegExp('(?=.*[0-9])');
const special = new RegExp('(?=.*[!@#\$%\^&\*])');
const length = new RegExp('(?=.{8,})');
//lower case validation check
if (lower.test(data)) {
lowerCase.classList.add('valid');
} else {
lowerCase.classList.remove('valid');
}
//upper case validation check
if (upper.test(data)) {
upperCase.classList.add('valid');
} else {
upperCase.classList.remove('valid');
}
//number case validation check
if (number.test(data)) {
digit.classList.add('valid');
} else {
digit.classList.remove('valid');
}
//special character case validation check
if (special.test(data)) {
specialChar.classList.add('valid');
} else {
specialChar.classList.remove('valid');
}
//minium length validation check
if (length.test(data)) {
minLenght.classList.add('valid');
} else {
minLenght.classList.remove('valid');
}
}
//show hide password
toggleBtn.onclick = function () {
if (pswrd.type === 'password') {
pswrd.setAttribute('type', 'text');
toggleBtn.classList.add('hide');
} else {
pswrd.setAttribute('type', 'password');
toggleBtn.classList.remove('hide');
}
}
</script>
</body>
</html>