-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunder.js
More file actions
58 lines (40 loc) · 1.35 KB
/
Copy pathunder.js
File metadata and controls
58 lines (40 loc) · 1.35 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
const form =document.getElementById("form");
const username =document.getElementById("username");
const password =document.getElementById("password");
form.addEventListener("submit", function(e){
e.preventDefault();
checkInput();
});
function checkInput(){
const usernameValue= username.value.trim();
const passwordValue= password.value.trim();
if (usernameValue === ""){
setErrorfor(username, "Sorry! email field can not be empty");
} else{
setSuccessfor(username);
}
if (passwordValue === ""){
setErrorfor(password, "Sorry! password field can not be empty");
}else if
(passwordValue.length < 6){
setErrorfor(password, "password must contain at least 6 characters!");
}else{
setSuccessfor(password);
}
}
function isEmail(email) {
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
}
function isValidPassword(password) {
return /^(?=.[a-z])(?=.[A-Z])(?=.\d)(?=.[@$!%?&])[A-Za-z\d@$!%?&]{8,}$/.test(password);
}
function setErrorfor(input, message){
const formControl = input.parentElement;
const small = formControl.querySelector("small");
small.innerText=message;
formControl.className = "form-control error";
}
function setSuccessfor(input){
const formControl = input.parentElement;
formControl.className = "form-control success";
}