-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuserregistrationform.js
More file actions
110 lines (104 loc) · 3.73 KB
/
Copy pathuserregistrationform.js
File metadata and controls
110 lines (104 loc) · 3.73 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
function nameCorrect(fname, lname, name_error){
let result = /^[A-Z]+$/.test(fname.value) && /^[A-Z]+$/.test(lname.value);
if(!result) name_error.style.visibility = "visible";
else name_error.style.visibility = "hidden";
console.log("nameCorrect:"+result);
return result;
}
function phoneCorrect(phone, phone_error){
let result = /^[0-9]+$/.test(phone.value) && phone.value.length == 10;
if(!result) phone_error.style.visibility = "visible";
else phone_error.style.visibility = "hidden";
console.log("phoneCorrect:"+result);
return result;
}
function dobCorrect(dob){
let today = new Date();
let cur_year = today.getFullYear().toString();
let cur_month = (today.getMonth()+1).toString();
let cur_date = today.getDate().toString();
let dob_string = dob.value;
let arr = dob_string.split("-");
if(cur_year<parseInt(arr[0])) return false;
else{
if(cur_month<parseInt(arr[1])) return false;
else{
if(cur_date<parseInt(arr[2])) return false;
}
}
return true;
}
function checkPwd(pwd, pwd_error){
if(pwd.length<6){
pwd_error.style.visibility="visible";
return false;
}
else{
if(/.*[a-z].*/.test(pwd) && /.*[A-Z].*/.test(pwd) && /.*\d.*/.test(pwd) && /.*\W.*/.test(pwd)) pwd_error.style.visibility = "hidden";
else{
pwd_error.style.visibility = "visibile";
return false;
}
}
return true;
}
function confirmPwd(pwd,cpwd,cpwd_error){
if(pwd===cpwd){
cpwd_error.style.visibility="hidden";
return true;
}
else{
cpwd_error.style.visibility="visible";
return false;
}
}
function getGender(male, female, others){
if(male) return "Male";
else
if(female) return "female"
return "Others";
}
function validateForm(){
let userForm = document.forms["user_form"];
let fname = userForm["fname"];
let lname = userForm["lname"];
let name_error = document.getElementById("name_error");
let male = document.getElementById("Male").checked;
let female = document.getElementById("Female").checked;
let others = document.getElementById("Others").checked;
let gender = getGender(male,female,others);
let email = userForm["email"];
let phone = userForm["pnum"];
let phone_error = document.getElementById("phone_error");
let dob = userForm["dob"];
let address = userForm["Address"].value;
let country = userForm["country"].value;
let pwd = userForm["pwd"].value;
let pwd_error = document.getElementById("pwd_error");
let cpwd = userForm["cpwd"].value;
let cpwd_error = document.getElementById("cpwd_error");
let agreeToTerms = userForm["user_agreement"].checked;
console.log("dobCorrect:"+dobCorrect(dob));
console.log("checkPwd correct:"+checkPwd(pwd,pwd_error));
console.log("ocnfirmPwd correct:"+confirmPwd(pwd,cpwd,cpwd_error));
if(nameCorrect(fname,lname,name_error) && phoneCorrect(phone,phone_error) && dobCorrect(dob) && confirmPwd(pwd,cpwd,cpwd_error) && checkPwd(pwd,pwd_error)){
user_obj = {
"firstname":fname.value,
"lastname":lname.value,
"gender":gender,
"email":email.value,
"phone":phone.value,
"dob":dob.value,
"address":address,
"country":country,
"pwd":CryptoJS.AES.encrypt(pwd, "G9MMa23PwYiPJejlM+8w+rQt4VY1JyAw0a+3wF/gvYKUPQWISBMpDZ6c5Ue+Lixh").toString()
};
console.log(user_obj);
return true;
}
else{
userForm["pwd"].value = "";
userForm["cpwd"].value = "";
return false;
}
}