-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
35 lines (28 loc) · 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
form=document.querySelector('form');
username=document.querySelector('#uname');
email=document.querySelector('#email');
pass=document.querySelector('#password');
unordered=document.querySelector('#error');
const re =
/^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i;
form.addEventListener("submit" , (e) => {
error_list = [];
if (username.value == ''){
error_list.push("username is empty");
}
if (re.test(email.value) == false) {
error_list.push("eamil is not valid");
}
if (pass.value.length <10) {
error_list.push("password is weak! choose an other password");
}
if (error_list.length > 0) {
e.preventDefault();
error_list.forEach((element) => {
console.log(element);
list_item=document.createElement('li');
list_item.innerText= element;
unordered.appendChild(list_item);
});
}
});