-
Notifications
You must be signed in to change notification settings - Fork 0
/
order_validation.js
151 lines (96 loc) · 4.13 KB
/
order_validation.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
function orderValidation(){
const senderName = document.getElementById("sender_name").value;
const senderEmail= document.getElementById("sender_email").value;
const senderPhone = document.getElementById("sender_phone").value;
const receiverName = document.getElementById("receiver_name").value;
const receiverPhone = document.getElementById("receiver_phone").value;
const deliveryTime = document.getElementById("delivery_time").value;
const pickupLocation= document.getElementById("loc1").value;
const pickupArea= document.getElementById("area1").value;
const nearestLandmark= document.getElementById("nearest_landmark").value;
const deliveryLocation= document.getElementById("loc2").value;
const deliveryArea= document.getElementById("area2").value;
const deliveryLandmark= document.getElementById("delivery_landmark").value;
let regName = /[a-zA-Z]/;
let regEmail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
let regPhone = /\d{10}/;
let senderNameErr = document.getElementById('sender_name_error');
let senderEmailErr = document.getElementById('sender_email_error');
let senderPhoneErr = document.getElementById('sender_phone_error');
let receiverNameErr = document.getElementById('receiver_name_error');
let receiverPhoneErr = document.getElementById('receiver_phone_error');
let deliveryTimeErr = document.getElementById('delivery_time_error');
let nearestLandmarkErr = document.getElementById('nearest_landmark_error');
let deliveryLandmarkErr = document.getElementById('delivery_landmark_error');
//if all the values are right , error message is not displayed
if((regName.test(senderName) && senderName!="")){
senderNameErr.style.display = "none";
}
if((regName.test(receiverName) && receiverName!="")){
receiverNameErr.style.display = "none";
}
if(regEmail.test(senderEmail) && senderEmail!=""){
senderEmailErr.style.display = "none";
}
if(regPhone.test(senderPhone) && senderPhone!=""){
senderPhoneErr.style.display = "none";
}
if(regPhone.test(receiverPhone) && receiverPhone!=""){
receiverPhoneErr.style.display = "none";
}
if(nearestLandmark!=""){
nearestLandmarkErr.style.display = "none";
}
if(deliveryLandmark!=""){
deliveryLandmarkErr.style.display = "none";
}
if(deliveryTime!=""){
deliveryTimeErr.style.display = "none";
}
//if the values are not right , error messages are displayed
//validating name
if(!(regName.test(senderName) && senderName!="")){
senderNameErr.innerText = "Invalid Name";
senderNameErr.style.display = "block";
return false;
}
if(!(regName.test(receiverName) && receiverName!="")){
receiverNameErr.innerText = "Invalid Name";
receiverNameErr.style.display = "block";
return false;
}
//validating email
if(!(regEmail.test(senderEmail) && senderEmail!="")){
senderEmailErr.innerText = "Invalid Email";
senderEmailErr.style.display = "block";
return false;
}
//validating phone
if(!(regPhone.test(senderPhone) && senderPhone!="")){
senderPhoneErr.innerText = "Invalid Phone";
senderPhoneErr.style.display = "block";
return false;
}
if(!(regPhone.test(receiverPhone) && receiverPhone!="")){
receiverPhoneErr.innerText = "Invalid Phone";
receiverPhoneErr.style.display = "block";
return false;
}
//validating landmark
if(nearestLandmark==""){
nearestLandmarkErr.innerText = "Landmark can't be empty";
nearestLandmarkErr.style.display = "block";
return false;
}
if(deliveryLandmark==""){
deliveryLandmarkErr.innerText = "Landmark can't be empty";
deliveryLandmarkErr.style.display = "block";
return false;
}
if(deliveryTime==""){
deliveryTimeErr.innerText = "Time can't be Empty";
deliveryTimeErr.style.display = "block";
return false;
}
return true;
}