Repository navigation
Expand file tree
/
Copy pathcodeform.js
More file actions
187 lines (139 loc) · 4.83 KB
/
Copy pathcodeform.js
File metadata and controls
187 lines (139 loc) · 4.83 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
const form = document.getElementById('form');
form.addEventListener('submit',(event) =>{
event.preventDefault();
validate();
})
//useful in validating email
const isvalidEmail = (emailVal) =>{
var atSymbol = emailVal.indexOf("@");
if(atSymbol < 1) return false;
var dot = emailVal.lastIndexOf('.');
if(dot <= atSymbol +3)return false;
if(dot === emailVal.length -1)return false;
return true;
}
//validating username
function validateusername(usernameVal){
usernameVal = usernameVal.trim();
if(usernameVal === ""){
setErrorMsg(username,'username cannot be blank');
}else if(usernameVal.length <= 2){
setErrorMsg(username,'username with min 3 characters');
}else{
setSuccessMsg(username);
}
}
//validating email
function validateemail(emailVal){
emailVal = emailVal.trim();
if(emailVal === ""){
setErrorMsg(email,'email cannot be blank');
}else if(!isvalidEmail(emailVal)){
setErrorMsg(email,'Not a valid email');
}else{
setSuccessMsg(email);
}
}
//validating college name
function validatecollegename(collegenameVal){
collegenameVal = collegenameVal.trim();
if(collegenameVal === ""){
setErrorMsg(institute,'the name cannot be blank');
}else if(collegenameVal.length <= 2){
setErrorMsg(institute,'the name with min 3 characters');
}else{
setSuccessMsg(institute);
}
}
//validating phone number
function validatephone(phoneVal){
phoneVal = phoneVal.trim();
if(phoneVal === ""){
setErrorMsg(phone, 'phone num cannot be blank');
}else if(phoneVal.length != 10){
setErrorMsg(phone,'Not a valid phone num');
}else {
setSuccessMsg(phone);
}
}
//validating password
function validatepassword(passwordVal){
passwordVal = passwordVal.trim();
if(passwordVal === ""){
setErrorMsg(password, 'password cannot be blank');
}else if(passwordVal.length <= 5){
setErrorMsg(password,'Minimum 6 characters');
}else {
setSuccessMsg(password);
}
}
//validating conform password
function validatecnfpass(cnfpasswordVal){
const passwordVal = document.getElementById('password').value.trim();
cnfpasswordVal = cnfpasswordVal.trim();
if(cnfpasswordVal === ""){
setErrorMsg(cnfpassword, 'password cannot be blank');
}else if(passwordVal !== cnfpasswordVal){
setErrorMsg(cnfpassword,'password are not matching');
}else {
setSuccessMsg(cnfpassword);
}
}
//validating checkbox
function validatecheckbox(checkobj){
if(checkobj.checked == true)
{
const par = checkobj.parentElement;
const small = par.querySelector('small');
small.innerHTML = "";
}
else
{
const par = checkobj.parentElement;
const small = par.querySelector('small');
small.innerHTML = "Agree to Terms & Conditions checkbox ";
}
}
function setErrorMsg(input, errormsg){
const formControl = input.parentElement;
const small = formControl.querySelector('small');
formControl.className = "form-control error"
small.innerHTML = errormsg;
}
function setSuccessMsg(input){
const formControl = input.parentElement;
formControl.className = "form-control success"
}
//checking is all valid for submitting form
function validate()
{
const usernameVal = document.getElementById('username').value;
finalSuccessMsg(usernameVal);
}
function sendcnts (usernameVal,sRate, count) {
let checkobj = document.getElementById('terms');
if(checkobj.checked) sRate += 1;
if(sRate === count)
{alert('registration successful');
swal({
title: "Welcome! " + usernameVal,
text: "Registration Successful",
icon: "success",
button: "Let's Code!",
});
// location.href = 'storedata.html?username=${usernameVal}';
}
}
function finalSuccessMsg (usernameVal) {
let formCon = document.getElementsByClassName('form-control');
var count = formCon.length ;
for(var i = 0; i < formCon.length ; i++)
{
if(formCon[i].className === "form-control success")
{var sRate = 0 + i ;
sendcnts(usernameVal,sRate,count);}
else{
return false;
}
}
}