-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidator.js
More file actions
30 lines (24 loc) · 824 Bytes
/
validator.js
File metadata and controls
30 lines (24 loc) · 824 Bytes
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
function validate() {
resetErrors();
let email = document.getElementById("email");
let password = document.getElementById("password");
let emailPattern = /^[a-zA-Z0-9._\+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
let valid = true;
if (password.value.length === 0) {
valid = false;
password.classList.add("error");
}
if (emailPattern.test(email.value) === false) {
valid = false;
email.classList.add("error");
}
if (valid === false) {
document.getElementById("error-box").style.display = "block";
}
return valid;
}
function resetErrors() {
document.getElementById("email").classList.remove("error");
document.getElementById("password").classList.remove("error");
document.getElementById("error-box").style.display = "none";
}