forked from Mritunjay19/SimpleHTMLForm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJavaScript.js
69 lines (69 loc) · 2.5 KB
/
JavaScript.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
function validate(op){
if(op==1){
var fname=document.getElementById("fname").value;
if(fname.length==0){
document.getElementById("s_fname").style.color="red";
document.getElementById("s_fname").innerHTML="Please enter a valid Name";
return false;
}
else {
document.getElementById("s_fname").style.color="green";
document.getElementById("s_fname").innerHTML="OK";
return true;
}
}
else if(op==2){
var fname=document.getElementById("lname").value;
if(fname.length==0){
document.getElementById("s_lname").style.color="red";
document.getElementById("s_lname").innerHTML="Please enter a valid Name";
return false;
}
else {
document.getElementById("s_lname").style.color="green";
document.getElementById("s_lname").innerHTML="OK";
return true;
}
}
else if(op==3){
var email=document.getElementById("eid").value;
if(email.indexOf("@")==-1||email.indexOf(".com")==-1){
document.getElementById("s_eid").style.color="red";
document.getElementById("s_eid").innerHTML="Please enter a valid EMail";
return false;
}
else {
document.getElementById("s_eid").style.color="green";
document.getElementById("s_eid").innerHTML="OK";
return true;
}
}
else if(op==4){
var pt=/^\d{10}$/;
var a=document.getElementById("phno").value;
if(a.match(pt)==null){
document.getElementById("s_phno").style.color="red";
document.getElementById("s_phno").innerHTML="Pleae enter a valid Ph.No.";
return false;
}
else{
document.getElementById("s_phno").style.color="green";
document.getElementById("s_phno").innerHTML="OK";
return true;
}
}
else{
var checkboxes = document.querySelectorAll('input[type="checkbox"]:checked');
if(checkboxes.length==0){
alert("You need to Select at least one language.");
return false;
}
else if(validate(1)&&validate(2)&&validate(3)&&validate(4)){
return true;
}
else{
alert("Please Fill All Details Correctly.");
return false;
}
}
}