-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
57 lines (49 loc) · 1.96 KB
/
Copy pathscript.js
File metadata and controls
57 lines (49 loc) · 1.96 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
const copyText = () => {
let input = document.getElementById("input");
input.value.length < 8
? addAnimation('notCoped')
: !/[a-z]/.test(input.value)
? addAnimation('notCoped')
: !/[A-Z]/.test(input.value)
? addAnimation('notCoped')
: !/[0-9]/.test(input.value)
? addAnimation('notCoped')
: !/[@$!%*?&]/.test(input.value)
? addAnimation('notCoped')
: input.value.includes(' ')
? addAnimation('notCoped')
:(navigator.clipboard.writeText(input.value), addAnimation('wasCoped'));
}
const addAnimation = (x) => {
let button = document.getElementById('copy');
button.classList.add(`${x}`);
setTimeout(() => {
button.classList.remove(`${x}`);
}, 1000);
}
document.addEventListener('DOMContentLoaded', () => {
const input = document.getElementById('input');
const lengthReq = document.getElementById('length');
const numberReq = document.getElementById('number');
const uppercaseReq = document.getElementById('uppercase');
const lowercaseReq = document.getElementById('lowercase');
const symbolReq = document.getElementById('symbol');
const validatePassword = () => {
const password = input.value;
const requirements = [
{ regex: /.{8,}/, element: lengthReq},
{ regex: /\d/,element: numberReq},
{ regex: /[A-Z]/,element: uppercaseReq},
{ regex: /[a-z]/,element: lowercaseReq},
{ regex: /[@$!%*?&]/,element: symbolReq}
];
requirements.forEach(requirement => {
requirement.regex.test(password)
? (requirement.element.classList.add('valid'), requirement.element.classList.remove('notValid'))
: password == ""
? (requirement.element.classList.remove('valid'), requirement.element.classList.remove('notValid'))
: (requirement.element.classList.add('notValid'), requirement.element.classList.remove('valid'))
});
};
input.addEventListener('input', validatePassword);
});