-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
44 lines (39 loc) · 1.1 KB
/
script.js
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
const upperCaseLetters = /[A-Z]/g;
const lowerCaseLetters = /[a-z]/g;
const numbers = /[0-9]/g;
const psw = document.getElementById('psw');
const cnfrm = document.getElementById('cnfrm');
const passValidate = function() {
console.log('Validating...');
if(psw.value != cnfrm.value) {
if(!psw.classList.contains("invalid") && !cnfrm.classList.contains("invalid")) {
console.log('Invalid.');
psw.classList.add("invalid");
cnfrm.classList.add("invalid");
}
}
else {
if(psw.classList.contains("invalid") && cnfrm.classList.contains("invalid")) {
console.log('Valid.');
psw.classList.remove("invalid");
cnfrm.classList.remove("invalid");
}
}
}
psw.onkeyup = passValidate;
cnfrm.onkeyup = passValidate;
const phone = document.getElementById('phone');
phone.onkeyup = function() {
const entry = phone.value;
if(entry.length == 10) {
if(!entry.match(upperCaseLetters) && !entry.match(lowerCaseLetters)) {
if(phone.classList.contains('invalid')) {
phone.classList.remove('invalid');
}
return;
}
}
if(!phone.classList.contains('invalid')) {
phone.classList.add('invalid');
}
}