-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathI_REGEX_STRONG_PASSWORD.html
More file actions
115 lines (113 loc) · 5.15 KB
/
I_REGEX_STRONG_PASSWORD.html
File metadata and controls
115 lines (113 loc) · 5.15 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>REGEX STRONG PASSWORD - STEP 11</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<style>
.is-Invalid{
border: 2px solid red;
background-color: #ffb1b14d;
}
.is-Valid{
border: 2px solid green;
}
.error-message{
color: red;
background-color: #ffb1b1;
padding: 3px 0px 3px 0px;
font-weight: 900;
}
</style>
</head>
<body>
<h1><b>REGEX STRONG PASSWORD - STEP 11</b></h1>
<div class="container mt-5">
<form id="myForm" novalidate>
<div class="form-group">
<label for="pwdInput">Password</label>
<input type="text" class="form-control" id="pwdInput" placeholder="Enter password">
<br />
<span id="pwdError" class="error-message"></span>
</div>
<br />
<button type="submit" class="btn btn-primary" id="submitBtn">Submit</button>
</form>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.min.js" integrity="sha384-0pUGZvbkm6XF6gxjEnlmuGrJXVbNuzT9qBBavbLwCsOGabYfZo0T0to5eqruptLy" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
<script>
//----------------------------------------------------------------
const validationMessage = {
password: {
minLength: "Password must be at least 8 characters long.",
uppercase: "Password must include at least one uppercase letter (A–Z).",
lowercase: "Password must include at least one lowercase letter (a–z).",
number: "Password must include at least one number (0–9).",
special: "Password must include at least one special character (e.g. -, !, @, #, $, %, ^, &, _, .).",
valid: "Strong password! Looks good."
}
};
//----------------------------------------------------------------
//----------------------------------------------------------------
LiveValidate({
input: document.getElementById("pwdInput"),
regex: /^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[-!@#$%^&_\.])[A-Za-z0-9-!@#$%^&_\.]{8,}$/i,
error: document.getElementById("pwdError"),
message: validationMessage.password,
type: "Password"
});
//----------------------------------------------------------------
//----------------------------------------------------------------
function LiveValidate({input, regex, error, message, type}){
input.addEventListener("input", () => {
if(type === "Password"){
const lenghtCheck = input.value.length >= 8;
const numberCheck = /\d/.test(input.value);
const upperCase = /[A-Z]/.test(input.value);
const lowerCase = /[a-z]/.test(input.value);
const specialChar = /[-!@#$%^&_\.]/.test(input.value);
if(!lenghtCheck)
{
error.innerText = message.minLength,
input.classList.add("is-Invalid"),
input.classList.remove("is-Valid")
}
else if(!numberCheck)
{
error.innerText = message.number,
input.classList.add("is-Invalid"),
input.classList.remove("is-Valid")
}
else if(!upperCase)
{
error.innerText = message.uppercase,
input.classList.add("is-Invalid"),
input.classList.remove("is-Valid")
}
else if(!lowerCase)
{
error.innerText = message.lowercase,
input.classList.add("is-Invalid"),
input.classList.remove("is-Valid")
}
else if(!specialChar)
{
error.innerText = message.special,
input.classList.add("is-Invalid"),
input.classList.remove("is-Valid")
}
else
{
error.innerText = "",
input.classList.remove("is-Invalid"),
input.classList.add("is-Valid")
}
}
});
}
//----------------------------------------------------------------
</script>
</body>
</html>