-
Notifications
You must be signed in to change notification settings - Fork 0
/
form_valid.js
228 lines (227 loc) · 6.38 KB
/
form_valid.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
<p>function CheckUp(frm)<br>
{ </p>
<p> if(frm.txtFname.value.length==0)<br>
{ <br>
alert("Blank First Name.....");<br>
frm.txtFname.focus();<br>
return false;<br>
}<br>
if(isNotAlphabets(frm.txtFname.value))<br>
{<br>
alert("The first name field contains invalid characters or spaces.\n Please re-enter your first name again.");<br>
return false;<br>
} <br>
if(frm.txtLname.value.length==0)<br>
{ <br>
alert("Blank last name ......");<br>
frm.txtLname.focus();<br>
return false;<br>
}<br>
if(isNotAlphabets(frm.txtLname.value))<br>
{<br>
alert("The last name field contains invalid characters or spaces.\n Please re-enter your last name again.");<br>
frm.txtLname.focus();<br>
return false;<br>
}<br>
// checking email address<br>
var email = document.forms[0].emailaddress.value<br>
if(email == "") <br>
{<br>
alert("Please enter a valid Email address.");<br>
frm.emailaddress.focus();<br>
return false;<br>
}<br>
if ( (email != "") && ((document.forms[0].emailaddress.value.indexOf("@")==-1) ||(document.forms[0].emailaddress.value.indexOf(".")==-1)))<br>
{<br>
alert ("Please enter a valid Email address.");<br>
frm.emailaddress.focus();<br>
return false;<br>
}</p>
<p>// end of email checking</p>
<p> <br>
if(frm.txtadd1.value.length==0)<br>
{ <br>
alert("Blank address ......");<br>
frm.txtadd1.focus();<br>
return false;<br>
}</p>
<p>if(frm.cboSex.value=="--Select--")<br>
{ <br>
alert("Invalid sex ......");<br>
frm.cboSex.focus();<br>
return false;<br>
}<br>
<br>
// phone number or mobile number check<br>
if (frm.txtMob.value.length==0)<br>
{<br>
if(frm.txtSTD.value.length==0 || !isNotAlphabets(frm.txtSTD.value) || frm.txtSTD.value.length >5 )<br>
{ <br>
alert("Invalid Std code ......");<br>
frm.txtSTD.focus();<br>
return false;<br>
}<br>
if(frm.txtPh.value.length==0 || !isNotAlphabets(frm.txtPh.value) || frm.txtPh.value.length >8 )<br>
{ <br>
alert("Invalid phone number ......");<br>
frm.txtPh.focus();<br>
return false;<br>
}<br>
}<br>
else<br>
{<br>
if(frm.txtMob.value.length==0 || !isNotAlphabets(frm.txtMob.value) || frm.txtMob.value.length != 10 )<br>
{ <br>
alert("Invalid Mobile number... ");<br>
frm.txtMob.focus();<br>
return false;<br>
}<br>
} <br>
// end of phone number or mobile number check<br>
if( !isDate())<br>
{<br>
return false; <br>
} <br>
if(frm.cboHostel.value=="--Select--")<br>
{ <br>
alert("Invalid Hostel Selection......");<br>
frm.cboHostel.focus();<br>
return false;<br>
}</p>
<p> if(frm.txtPassword.value.length < 6 )<br>
{ <br>
alert("Password to short ......");<br>
frm.txtPassword.focus();<br>
return false;<br>
}<br>
if(frm.txtPassword.value.length==0 || frm.txtPassword.value.length < 6 )<br>
{ <br>
alert("Blank password ......");<br>
frm.txtPassword.focus();<br>
return false;<br>
}<br>
if(frm.txtRePassword.value==0)<br>
{ <br>
alert("Retype the password again ......");<br>
frm.txtRePassword.focus();<br>
return false;<br>
}<br>
if(frm.txtPassword.value != frm.txtRePassword.value)<br>
{ <br>
alert("Password and Retype password is not same ......");<br>
frm.txtRePassword.focus();<br>
return false;<br>
}<br>
<br>
return true<br>
}<br>
<br>
///// end of function checkup <br>
<br>
//FUNCTIONS FOR DATE CHECKING<br>
function isDate()<br>
{<br>
var yy,mm,dd;<br>
var im,id,iy;<br>
var present_date = new Date();<br>
yy = 1900 + present_date.getYear();<br>
if (yy > 3000)<br>
{<br>
yy = yy - 1900;<br>
}<br>
mm = present_date.getMonth();<br>
dd = present_date.getDate();<br>
im = document.forms[0].month.selectedIndex;<br>
id = document.forms[0].day.selectedIndex;<br>
iy = document.forms[0].year.selectedIndex;<br>
var entered_month = document.forms[0].month.options[im].value;<br>
var invalid_month = document.forms[0].month.options[im].value - 1; <br>
var entered_day = document.forms[0].day.options[id].value; <br>
var entered_year = document.forms[0].year.options[iy].value; <br>
if ( (entered_day == 0) || (entered_month == 0) || (entered_year == 0) )<br>
{<br>
alert("Please enter your birhtday");<br>
return false;<br>
}<br>
if ( is_greater_date(entered_year,entered_month,entered_day,yy,mm,dd) && is_valid_day(invalid_month,entered_day,entered_year) )<br>
{<br>
return true; <br>
}<br>
return false;<br>
}</p>
<p> function is_greater_date(entered_year,entered_month,entered_day,yy,mm,dd)<br>
{<br>
if (entered_year > yy)<br>
{<br>
alert("The birthday field is entered incorrectly. The year entered exceeds the current year.");<br>
return false;<br>
}<br>
if (entered_year == yy)<br>
{<br>
if (entered_month > mm)<br>
{<br>
alert("The birthday field is entered incorrectly.");<br>
return false;<br>
}<br>
if (entered_month == mm)<br>
{<br>
if (entered_day > dd)<br>
{<br>
alert("The birthday field is entered incorrectly.");<br>
return false;<br>
}<br>
}<br>
}<br>
return true;<br>
}</p>
<p>function is_valid_day(entered_month,entered_day,entered_year)<br>
{<br>
if ((entered_year % 4) == 0) <br>
{ <br>
var days_in_month = "312931303130313130313031";<br>
}<br>
else <br>
{ <br>
var days_in_month = "312831303130313130313031";<br>
} <br>
var months = new Array("January","February","March","April","May","June","July","August","September","October","November","December");<br>
if (entered_month != -1)<br>
{<br>
if (entered_day > days_in_month.substring(2*entered_month,2*entered_month+2))<br>
{<br>
alert ("The birthday field is entered wrongly (the day field value exceeds the number of days for the month entered).");<br>
return false;<br>
}<br>
}<br>
return true;<br>
}</p>
<p> </p>
<p> </p>
<p>// END OF DATE CHECKING FUNCTION<br>
<br>
<br>
<br>
// func tion for alphabatic<br>
<br>
function isNotAlphabets(str)<br>
{<br>
for (var i = 0; i < str.length; i++)<br>
{<br>
var ch = str.substring(i, i + 1);<br>
if((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) <br>
{<br>
return true;<br>
}<br>
}<br>
return false;<br>
}<br>
</p>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
</body>
</html>