forked from codeb1ooded/RTI_Automation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdate_validation_add_rti.js
More file actions
200 lines (186 loc) · 5.63 KB
/
date_validation_add_rti.js
File metadata and controls
200 lines (186 loc) · 5.63 KB
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
function validatedate1(inputText) {
var dateformat = /^(\d{4})-(\d{1,2})-(\d{1,2})/;
// Match the date format through regular expression
if(inputText.value.match(dateformat)) {
document.add_rti.date_of_receipt.focus();
//Test which seperator is used '/' or '-'
var opera1 = inputText.value.split('/');
var opera2 = inputText.value.split('-');
lopera1 = opera1.length;
lopera2 = opera2.length;
// Extract the string into month, date and year
if (lopera1>1) {
var pdate = inputText.value.split('/');
} else if (lopera2>1) {
var pdate = inputText.value.split('-');
}
var dd = parseInt(pdate[2]);
var mm = parseInt(pdate[1]);
var yy = parseInt(pdate[0]);
// Create list of days of a month [assume there is no leap year by default]
var ListofDays = [31,28,31,30,31,30,31,31,30,31,30,31];
if(mm >12){
document.add_rti.date_of_receipt.focus();
alert('Month should be less than twelve!!! \nInvalid date format!');
return false;
}
if (mm==1 || mm>2) {
if (dd>ListofDays[mm-1]) {
document.add_rti.date_of_receipt.focus();
alert('Date exceeded!!! \nInvalid date format!');
return false;
}
else {
return true;
}
}
if (mm==2) {
var lyear = false;
if ( (!(yy % 4) && yy % 100) || !(yy % 400)) {
lyear = true;
}
if ((lyear==false) && (dd>=29)) {
alert('Date exceeded!!! \nInvalid date format!');
document.add_rti.date_of_receipt.focus();
return false;
}
else if ((lyear==true) && (dd>29)) {
alert('Date exceeded!!! \nInvalid date format!');
document.add_rti.date_of_receipt.focus();
return false;
}
else {
return true;
}
}
}
else {
alert("Date format is not correct!!!! \nInvalid date format!");
document.add_rti.date_of_receipt.focus();
return false;
}
}
function validatedate2(inputText) {
var dateformat = /^(\d{4})-(\d{1,2})-(\d{1,2})/;
// Match the date format through regular expression
if(inputText.value.match(dateformat)) {
document.add_rti.date_of_receipt_cio.focus();
//Test which seperator is used '/' or '-'
var opera1 = inputText.value.split('/');
var opera2 = inputText.value.split('-');
lopera1 = opera1.length;
lopera2 = opera2.length;
// Extract the string into month, date and year
if (lopera1>1) {
var pdate = inputText.value.split('/');
} else if (lopera2>1) {
var pdate = inputText.value.split('-');
}
var dd = parseInt(pdate[2]);
var mm = parseInt(pdate[1]);
var yy = parseInt(pdate[0]);
if(mm >12){
document.add_rti.date_of_receipt_cio.focus();
alert('Month should be less than twelve!!! \nInvalid date format!');
return false;
}
// Create list of days of a month [assume there is no leap year by default]
var ListofDays = [31,28,31,30,31,30,31,31,30,31,30,31];
if (mm==1 || mm>2) {
if (dd>ListofDays[mm-1]) {
document.add_rti.date_of_receipt_cio.focus();
alert('Date exceeded!!! \nInvalid date format!');
return false;
}
else {
return true;
}
}
if (mm==2) {
var lyear = false;
if ( (!(yy % 4) && yy % 100) || !(yy % 400)) {
lyear = true;
}
if ((lyear==false) && (dd>=29)) {
alert('Date exceeded!!! \nInvalid date format!');
document.add_rti.date_of_receipt_cio.focus();
return false;
}
else if ((lyear==true) && (dd>29)) {
alert('Date exceeded!!! \nInvalid date format!');
document.add_rti.date_of_receipt_cio.focus();
return false;
}
else {
return true;
}
}
}
else {
document.add_rti.date_of_receipt_cio.focus();
alert("Date format is not correct!!!! \nInvalid date format!");
return false;
}
}
function validatedate3(inputText) {
var dateformat = /^(\d{4})-(\d{1,2})-(\d{1,2})/;
// Match the date format through regular expression
if(inputText.value.match(dateformat)) {
document.add_rti.fee_deposit_date.focus();
//Test which seperator is used '/' or '-'
var opera1 = inputText.value.split('/');
var opera2 = inputText.value.split('-');
lopera1 = opera1.length;
lopera2 = opera2.length;
// Extract the string into month, date and year
if (lopera1>1) {
var pdate = inputText.value.split('/');
} else if (lopera2>1) {
var pdate = inputText.value.split('-');
}
var dd = parseInt(pdate[2]);
var mm = parseInt(pdate[1]);
var yy = parseInt(pdate[0]);
// Create list of days of a month [assume there is no leap year by default]
var ListofDays = [31,28,31,30,31,30,31,31,30,31,30,31];
if(mm >12){
document.add_rti.fee_deposit_date.focus();
alert('Month should be less than twelve!!! \nInvalid date format!');
return false;
}
if (mm==1 || mm>2) {
if (dd>ListofDays[mm-1]) {
document.add_rti.fee_deposit_date.focus();
alert('Date exceeded!!! \nInvalid date format!');
return false;
}
else {
return true;
}
}
if (mm==2) {
var lyear = false;
if ( (!(yy % 4) && yy % 100) || !(yy % 400)) {
lyear = true;
}
if ((lyear==false) && (dd>=29)) {
alert('Date exceeded!!! \nInvalid date format!');
document.add_rti.fee_deposit_date.focus();
return false;
}
else if ((lyear==true) && (dd>29)) {
alert('Date exceeded!!! \nInvalid date format!');
document.add_rti.fee_deposit_date.focus();
return false;
}
else {
return true;
}
}
}
else {
document.add_rti.fee_deposit_date.focus();
alert("Date format is not correct!!!! \nInvalid date format!");
return false;
}
}