-
Notifications
You must be signed in to change notification settings - Fork 2
/
reg_loginformvalidation.js
264 lines (248 loc) · 6.78 KB
/
reg_loginformvalidation.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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
var nameFlag=emailFlag=usernameFlag=passwordFlag=cnfmpasswordFlag=mobileFlag=addressFlag=blockFlag=false;
function checkFN(name) { //check full name
var nameExp =/^([a-z]+\s)*[a-z]+$/i;
if (name.length == 0) {
msg = "";
nameFlag = false;
}
else if (!nameExp.test(name)) {
msg = "Invalid Name";
color = "red";
nameFlag = false;
}
else {
msg = "Valid Name";
color = "green";
nameFlag = true;
}
document.getElementById('name_msg').style.color = color;
document.getElementById('name_msg').innerHTML = msg;
}
function checkUN(uname,id) { //check username
var unameExp = /^[a-z0-9]\w{4,19}$/i;
if (uname.length == 0) {
msg = "";
usernameFlag = false;
}
else if (!unameExp.test(uname)) {
msg = "Invalid Username";
color = "red";
usernameFlag = false;
}
else {
msg = "Valid Username";
color = "green";
usernameFlag = true;
if (id=="reg_username_msg")
ajaxexists(uname,"uname");
}
document.getElementById(id).style.color = color;
document.getElementById(id).innerHTML = msg;
}
function checkPWD(pwd,id) { //check password
var pwdExp = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,20}$/;
if (pwd.length == 0) {
msg = "";
passwordFlag = false;
}
else if (!pwdExp.test(pwd)) {
msg = "Invalid password";
color = "red";
passwordFlag = false;
}
else {
msg = "Valid password";
color = "green";
passwordFlag = true;
}
document.getElementById(id).style.color = color; //id is used because same function use for login form where id is different
document.getElementById(id).innerHTML = msg;
if(id=="reg_pwd_msg") //did this cus if user enters a valid passord after entering a valid comfirmation password
confirmPWD(document.forms[1].cnfm_password.value);
}
function confirmPWD(cpassword) { //check 2nd password
if (cpassword.length == 0) {
msg = "";
cnfmpasswordFlag = false;
}
else if (document.getElementById('reg_pwd_msg').innerHTML== 'Invalid password') {
msg="enter valid password first";
color="red";
cnfmpasswordFlag=false;
}
else
{
var firstPwd = document.forms[1].password.value;
if (firstPwd.length==0) {
msg="";
cnfmpasswordFlag=false;
color="white"; //need to enter or gives not defined error
}
else if (cpassword!=firstPwd) {
msg = "passwords don't match";
color = "red";
cnfmpasswordFlag = false;
}
else {
msg = "they match";
color = "green";
cnfmpasswordFlag = true;
}
}
document.getElementById('cfmpwd_msg').style.color = color;
document.getElementById('cfmpwd_msg').innerHTML = msg;
}
function checkMBL(mobile) { //check mobile num
if (document.forms[1].country_code.value=='+973') {
var numExp= /^(17|32|33|34|35|36|37|38|39)[0-9]{6}$/;
}
else if (document.forms[1].country_code.value=='+966') {
var numExp= /^(54|56|57|58|59)[0-9]{6,8}$/;
}
else if(document.forms[1].country_code.value=='+971') {
var numExp= /^(50|52|54|55|56|58)[0-9]{6,8}$/;
}
if (mobile.length == 0) {
msg = "";
mobileFlag = false;
}
else if (!numExp.test(mobile)) {
msg = "Invalid mobile number";
color = "red";
mobileFlag = false;
}
else {
msg = "Valid mobile number";
color = "green";
mobileFlag = true;
ajaxexists(mobile,"mobile");
}
document.getElementById('mobile_msg').style.color = color;
document.getElementById('mobile_msg').innerHTML = msg;
}
function checkAddr(addr) { //check if building is 3-4 digits
var addrExp = /^[0-9]{3,4}$/;
if (addr.length == 0) {
msg = "";
addressFlag = false;
}
else if (!addrExp.test(addr)) {
msg = "Invalid building";
color = "red";
addressFlag = false;
}
else {
msg = "Valid building";
color = "green";
addressFlag = true;
}
document.getElementById('addr_msg').style.color = color;
document.getElementById('addr_msg').innerHTML = msg;
}
function checkBlock(addr) { //check if block is 3-4 digits
var addrExp = /^[0-9]{3,4}$/;
if (addr.length == 0) {
msg = "";
blockFlag = false;
}
else if (!addrExp.test(addr)) {
msg = "Invalid block";
color = "red";
blockFlag = false;
}
else {
msg = "Valid block";
color = "green";
blockFlag = true;
}
document.getElementById('block_msg').style.color = color;
document.getElementById('block_msg').innerHTML = msg;
}
function checkMAIL(mail) { //check mail format
var mailExp =/^[a-zA-Z0-9._-]+@([a-zA-Z0-9-]+\.)+[a-zA-Z.]{2,5}$/;
if (mail.length == 0) {
msg = "";
emailFlag = false;
}
else if (!mailExp.test(mail)) {
msg = "Invalid mail format";
color = "red";
emailFlag = false;
}
else {
msg = "Valid mail";
color = "green";
emailFlag = true;
ajaxexists(mail,"email");
}
document.getElementById('mail_msg').style.color = color;
document.getElementById('mail_msg').innerHTML = msg;
}
function GetXmlHttpObject() {
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
catch (e)
{ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
}
return xmlHttp;
}
function ajaxexists(word,type){
var xmlHttp= GetXmlHttpObject();
if (xmlHttp==null) {
alert("Your browser does not support AJAX!");
return false;
}
var url="checkunameemailmobile.php"
if (type=="uname")
url=url+"?uname="+word;
else if (type=="email")
url=url+"?email="+word;
else if (type=="mobile")
url=url+"?mobile="+word;
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4){
ajax_checking=xmlHttp.responseText;
reGajaxmsgs(word,type,ajax_checking);
}
}
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function reGajaxmsgs(word, type, result){
if (type=="uname" && result=="present") {
document.getElementById('reg_username_msg').style.color ="red";
document.getElementById('reg_username_msg').innerHTML ="Username already exists";
usernameFlag=false;
}
else if(type=="email" && result=="present"){
document.getElementById('mail_msg').style.color ="red";
document.getElementById('mail_msg').innerHTML ="Email already registered";
emailFlag=false;
}
else if(type=="mobile" && result=="present"){
document.getElementById('mobile_msg').style.color ="red";
document.getElementById('mobile_msg').innerHTML ="Number already registered";
mobileFlag=false;
}
}
function checkRegistrationInputs(){
document.forms[1].JSEnabled.value="TRUE";
return (nameFlag&&usernameFlag&&passwordFlag&&cnfmpasswordFlag&&mobileFlag&&addressFlag&&emailFlag);
}
function checkLoginInputs(){
document.forms[1].JSEnabled.value="TRUE";
checkUN(document.getElementById('fillemail').value, 'login_username_msg');
checkPWD(document.getElementById('fillpwd').value, 'login_pwd_msg');
console.log('entered')
return (usernameFlag&&passwordFlag);
}