-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
90 lines (73 loc) · 2.59 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
const name = document.getElementById("name")
const email = document.getElementById("email")
const pass = document.getElementById("pass")
const vpass = document.getElementById("vpass")
const btn = document.getElementById("b1")
let n = undefined;
let em = undefined;
let p = undefined;
let vp = undefined;
btn.addEventListener("click", e => {
checkdata()
console.log("hi")
if (n !== true || em !== true || p !== true || vp !== true) {
e.preventDefault();
console.log("if")
}
});
function checkdata() {
const nval = name.value.trim();
const eval = email.value.trim();
const pval = pass.value.trim();
const vpval = vpass.value.trim();
if (nval === "") {
seterror(name, "Enter ur Name*")
n = false;
} else {
setnoerror(name)
n = true;
}
if (eval === "") {
seterror(email, "Enter ur Email*")
em = false;
} else if (!remail(eval)) {
seterror(email, "Enter a valid email")
em = false;
}
else {
setnoerror(email)
em = true;
}
if (pval === "") {
seterror(pass, "Enter Password*")
p = false;
} else {
setnoerror(pass)
p = true;
}
if (vpval === "") {
seterror(vpass, "Wrong Password*")
vp = false;
} else if (pval !== vpval) {
seterror(vpass, "Wrong Password")
vp = false;
}
else {
setnoerror(vpass)
vp = true;
}
}
function seterror(input, message) {
const formparts = input.parentElement;
formparts.className = 'form-parts error';
const small = formparts.querySelector('small')
small.innerText = message;
console.log("this is ur mssg")
}
function setnoerror(input) {
const formparts = input.parentElement;
formparts.className = 'form-parts noerror';
}
function remail(eval) {
return /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(eval)
}