-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
114 lines (88 loc) · 2.69 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
let form = document.querySelector(".form1")
let naam = document.querySelector("#name")
let email = document.querySelector("#email")
let password = document.querySelector("#password")
let confirmP = document.querySelector("#conpassword")
let btn = document.querySelector("#signup")
let arr = []
let id = 1;
//let emailregex = /^[a-zA-Z0-9+_.-]+@[a-zA-Z0-9.-]+$/;
form.addEventListener('submit', validateForm)
function validateForm(e) {
e.preventDefault() // form will never get submitted unless all condition passed
let urname = naam.value;
let uremail = email.value;
let urpassword = password.value;
let urconfirmP = confirmP.value;
// name
if (checkname(urname) < 2) {
let nameerror = document.querySelector(".name")
nameerror.innerHTML = " Name must be at least 2 words!!"
}
//email
else if (validateEmail(uremail)==false ) {
let emailerror = document.querySelector(".email")
emailerror.innerHTML = " e-mail is invalid"
}
//password
else if (validatePassword(urpassword, urname, uremail) == false) {
let passerror = document.querySelector(".pass")
passerror.innerHTML = " Password is invalid"
}
//confirmpassword
else if (urpassword != urconfirmP) {
let conerror = document.querySelector(".confirm")
conerror.innerHTML = " Password is not matching"
}
//checking already registered
else if(checkemail(uremail)==false)
{
let message = document.querySelector(".message")
message.innerHTML="Already Registered!!";
message.style.color="red"
}
else {
let msg = document.querySelector(".success")
msg.innerHTML = "Success!"
let obj = { id: id++, urname, uremail, urpassword }
arr.push(obj);
naam.value = '' ;
email.value = '' ;
password.value = '' ;
confirmP.value = '' ;
//storing data in local storage
localStorage.setItem("data", JSON.stringify(arr));
window.location.href = "./login.html";
}
}
function checkname(urname) {
urname.trim()
let arr = urname.split(' ')
return arr.length
}
function validatePassword(urpassword, urname, uremail) {
if ((/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{3,}$/.test(urpassword)) && urpassword != urname && urpassword != uremail)
{
return true
}
return false
}
function checkemail(uremail)
{
for( t of arr)
{
if(t.uremail==uremail)
{
return false;
}
}
return true;
}
function validateEmail(uremail)
{
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(uremail))
{
return (true)
}
return (false)
}