-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstudent.js
77 lines (46 loc) · 1.71 KB
/
student.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
function clearErrors(){
errors = document.getElementsByClassName('formerror');
for(let item of errors)
{
item.innerHTML = "";
}
//it will make the error input clear when the users will input the correct information...
}
function seterror(id, error){
element = document.getElementById(id);
element.getElementsByClassName('formerror')[0].innerHTML = error;
}
function validateForm(){
var returnval = true;
clearErrors();
var name = document.forms['myForm']["fname"].value;
if (name.length<5){
seterror("name", "*Length of name is too short");
returnval = false;
}
if (name.length == 0){
seterror("name", "*Length of name cannot be zero!");
returnval = false;
}
var email = document.forms['myForm']["femail"].value;
if (email.length>15){
seterror("email", "*Email length is too long");// in email id put error using seterror function that it is not a valid email
returnval = false;
}
var phone = document.forms['myForm']["fphone"].value;
if (phone.length != 10){
seterror("phone", "*Phone number should be of 10 digits!");
returnval = false;
}
var password = document.forms['myForm']["fpass"].value;
if (password.length < 8){
seterror("pass", "*Password should be atleast 8 characters long!");
returnval = false;
}
var cpassword = document.forms['myForm']["fcpass"].value;
if (cpassword != password){
seterror("cpass", "*Password and Confirm password should match!");
returnval = false;
}
return returnval;
}