-
Notifications
You must be signed in to change notification settings - Fork 0
/
reg.js
239 lines (219 loc) · 5.65 KB
/
reg.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
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
function CheckUp()
{
alert("Blank UserName.....");
var frm=document.regform;
if(frm.username.value.length==0)
{
alert("Blank UserName.....");
frm.username.focus();
return false;
}
if(isNotAlphabets(frm.username.value))
{
alert("The USERNAME field contains invalid characters or spaces.\n Please re-enter your first name again.");
return false;
}
if(frm.first_name.value.length==0)
{
alert("Blank last name ......");
frm.txtLname.focus();
return false;
}
if(isNotAlphabets(frm.first_name.value))
{
alert("The USERNAME field contains invalid characters or spaces.\n Please re-enter your first name again.");
return false;
}
if(isNotAlphabets(frm.last_name.value))
{
alert("The last name field contains invalid characters or spaces.\n Please re-enter your last name again.");
frm.txtLname.focus();
return false;
}
if(frm.last_name.value.length==0)
{
alert("Blank last name ......");
frm.txtLname.focus();
return false;
}
// checking email address
var email = document.forms[0].emailaddress.value
if(email == "")
{
alert("Please enter a valid Email address.");
frm.email.focus();
return false;
}
if ( (email != "") && ((document.forms[0].email.value.indexOf("@")==-1) ||(document.forms[0].email.value.indexOf(".")==-1)))
{
alert ("Please enter a valid Email address.");
frm.email.focus();
return false;
}
// end of email checking
if(frm.txtadd1.value.length==0)
{
alert("Blank address ......");
frm.txtadd1.focus();
return false;
}
if(frm.cboSex.value=="--Select--")
{
alert("Invalid sex ......");
frm.cboSex.focus();
return false;
}
// phone number or mobile number check
if (frm.txtMob.value.length==0)
{
if(frm.txtSTD.value.length==0 || !isNotAlphabets(frm.txtSTD.value) || frm.txtSTD.value.length >5 )
{
alert("Invalid Std code ......");
frm.txtSTD.focus();
return false;
}
if(frm.txtPh.value.length==0 || !isNotAlphabets(frm.txtPh.value) || frm.txtPh.value.length >8 )
{
alert("Invalid phone number ......");
frm.txtPh.focus();
return false;
}
}
else
{
if(frm.txtMob.value.length==0 || !isNotAlphabets(frm.txtMob.value) || frm.txtMob.value.length != 10 )
{
alert("Invalid Mobile number... ");
frm.txtMob.focus();
return false;
}
}
// end of phone number or mobile number check
if( !isDate())
{
return false;
}
if(frm.cboHostel.value=="--Select--")
{
alert("Invalid Hostel Selection......");
frm.cboHostel.focus();
return false;
}
if(frm.txtPassword.value.length < 6 )
{
alert("Password to short ......");
frm.txtPassword.focus();
return false;
}
if(frm.txtPassword.value.length==0 || frm.txtPassword.value.length < 6 )
{
alert("Blank password ......");
frm.txtPassword.focus();
return false;
}
if(frm.txtRePassword.value==0)
{
alert("Retype the password again ......");
frm.txtRePassword.focus();
return false;
}
if(frm.txtPassword.value != frm.txtRePassword.value)
{
alert("Password and Retype password is not same ......");
frm.txtRePassword.focus();
return false;
}
return true
}
///// end of function checkup
//FUNCTIONS FOR DATE CHECKING
function isDate()
{
var yy,mm,dd;
var im,id,iy;
var present_date = new Date();
yy = 1900 + present_date.getYear();
if (yy > 3000)
{
yy = yy - 1900;
}
mm = present_date.getMonth();
dd = present_date.getDate();
im = document.forms[0].month.selectedIndex;
id = document.forms[0].day.selectedIndex;
iy = document.forms[0].year.selectedIndex;
var entered_month = document.forms[0].month.options[im].value;
var invalid_month = document.forms[0].month.options[im].value - 1;
var entered_day = document.forms[0].day.options[id].value;
var entered_year = document.forms[0].year.options[iy].value;
if ( (entered_day == 0) || (entered_month == 0) || (entered_year == 0) )
{
alert("Please enter your birhtday");
return false;
}
if ( is_greater_date(entered_year,entered_month,entered_day,yy,mm,dd) && is_valid_day(invalid_month,entered_day,entered_year) )
{
return true;
}
return false;
}
function is_greater_date(entered_year,entered_month,entered_day,yy,mm,dd)
{
if (entered_year > yy)
{
alert("The birthday field is entered incorrectly. The year entered exceeds the current year.");
return false;
}
if (entered_year == yy)
{
if (entered_month > mm)
{
alert("The birthday field is entered incorrectly.");
return false;
}
if (entered_month == mm)
{
if (entered_day > dd)
{
alert("The birthday field is entered incorrectly.");
return false;
}
}
}
return true;
}
function is_valid_day(entered_month,entered_day,entered_year)
{
if ((entered_year % 4) == 0)
{
var days_in_month = "312931303130313130313031";
}
else
{
var days_in_month = "312831303130313130313031";
}
var months = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
if (entered_month != -1)
{
if (entered_day > days_in_month.substring(2*entered_month,2*entered_month+2))
{
alert ("The birthday field is entered wrongly (the day field value exceeds the number of days for the month entered).");
return false;
}
}
return true;
}
// END OF DATE CHECKING FUNCTION
// func tion for alphabatic
function isNotAlphabets(str)
{
for (var i = 0; i < str.length; i++)
{
var ch = str.substring(i, i + 1);
if((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch))
{
return true;
}
}
return false;
}