-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
73 lines (52 loc) · 2.06 KB
/
main.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
//for remove error after validation
function clearErrors() {
errors = document.getElementsByClassName('error');
for (let item of errors) {
item.innerHTML = "";
}
}
//form validation
function validateform() {
var returnval = true;
clearErrors();
var name = document.forms['myform']["fname"].value;
if (name.length <= 5) {
document.querySelector(".name-error").innerHTML = "*username should be 6 digit or more";
document.getElementById("name-error").classList.add("fail");
returnval = false;
} else {
document.getElementById("name-error").classList.add("success");
}
var pass = document.forms['myform']["fpass"].value;
if (pass.match(/[!@#\$%\^&\*]/)) {
document.getElementById("pass-error").classList.add("success");
} else {
document.querySelector(".pass-error").innerHTML = "*one special character required";
returnval = false;
document.getElementById("pass-error").classList.add("fail");
}
if (pass.match(/[0-9]/)) {
document.getElementById("pass-error").classList.add("success");
} else {
document.querySelector(".pass-error").innerHTML = "*one digit required";
returnval = false;
document.getElementById("pass-error").classList.add("fail");
}
var cpassword = document.forms['myform']["fcpass"].value;
if (cpassword != pass) {
document.querySelector(".cpass-error").innerHTML = "*Password and Confirm password should same";
document.getElementById("cpass-error").classList.add("fail");
returnval = false;
} else {
document.getElementById("cpass-error").classList.add("success");
}
var phone = document.forms['myform']["fphone"].value;
if (isNaN(phone)) {
document.querySelector(".phone-error").innerHTML = "*you can enter only digits";
document.getElementById("phone-error").classList.add("fail");
returnval = false;
} else {
document.getElementById("phone-error").classList.add("success");
}
return returnval;
}