-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
224 lines (196 loc) · 5.69 KB
/
app.js
File metadata and controls
224 lines (196 loc) · 5.69 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
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
$(document).ready(function () {
var inputs = $("input");
var form = $("#myform");
var name = $("#name");
var email = $("#email");
var pass = $("#pass");
var cpass = $("#cpass");
$("#toggle").change(function () {
// Check the checkbox state
if ($(this).is(":checked")) {
// Changing type attribute
pass.attr("type", "text");
cpass.attr("type", "text");
// Change the Text
$("#toggleText").text("Hide");
} else {
// Changing type attribute
pass.attr("type", "password");
cpass.attr("type", "password");
// Change the Text
$("#toggleText").text("Show");
}
});
// close modal
$(".conte").click(function () {
if ($(this).hasClass("modals")) {
} else {
$(this).css("display", "none");
}
});
// prevent spaces to be entered at the begining of fields
function nospace(input) {
$(input).keydown(function (event) {
if (input.val().length === 0 && event.which === 32) {
event.preventDefault();
}
});
}
nospace(name);
nospace(email);
nospace(pass);
nospace(cpass);
// trimSpace(inout); remove spaces on all the end and all input on blur(after fucus on the filed is loose)
function blurTrim(input) {
$(input).blur(function () {
$(this).val($(this).val().trim());
});
}
blurTrim(name);
blurTrim(email);
blurTrim(pass);
blurTrim(cpass);
// validate if password is equal to confirm password
function validatePassAndCpass() {
var vraipass = pass.val();
var vraicpass = cpass.val();
let pwdmt = $(".pswdmatch");
if (vraipass.length == 0 || vraicpass.length == 0) {
pwdmt.css("color", "red");
$(pass).css("border", "1px solid red");
$(cpass).css("border", "1px solid red");
return false;
} else {
if (vraipass == vraicpass) {
pwdmt.html("Password match");
pwdmt.css("color", "green");
$(pass).css("border", "1px solid green");
$(cpass).css("border", "1px solid green");
return true;
} else {
pwdmt.html("Password does not match");
pwdmt.css("color", "red");
$(pass).css("border", "1px solid red");
$(cpass).css("border", "1px solid red");
return false;
}
return true;
}
}
// validate name and paswords feilds to be more than 2 in lenght
function valall(x) {
let field = $(x).attr("id");
$(x).keyup(function () {
if ($(x).val().length <= 2) {
$(x).css("border", "1px solid red");
$(x).next().css("display", "inline-block");
$(x)
.next()
.html(field + "" + " should be atleat 2 characters");
$(x).next().css("color", "red");
} else {
$(x).css("border", "1px solid green");
$(x).next().css("color", "green");
$(x).next().html("fields is correct");
}
});
}
valall(name);
valall(pass);
valall(cpass);
// validatepassword
function validatesPass() {
if ($(pass).val().length < 2) {
$(pass).css("border", "1px solid red");
$(pass).next().css("display", "inline-block");
return false;
} else {
$(pass).css("border", "1px solid green");
$(pass).next().css("display", "none");
return true;
}
}
// validatepassword
function validatescPass() {
if ($(cpass).val().length < 2) {
$(cpass).css("border", "1px solid red");
$(cpass).next().css("display", "inline-block");
return false;
} else {
$(cpass).css("border", "1px solid green");
$(cpass).next().css("display", "none");
return true;
}
}
// validateemail
// display notice message if fields empty on submit
function emptyEmail() {
if ($(email).val().length < 2) {
$(email).css("border", "1px solid red");
$(email).next().css("display", "inline-block");
return false;
} else {
return true;
}
}
// keyup email
$(email).keyup(function () {
if (validateEmails()) {
$(email).css("border", "1px solid green");
$(email).next().css("display", "inline-block");
$(email).next().html("email is valid");
$(email).next().css("color", "green");
} else {
$(email).css("border", "1px solid red");
$(email).next().css("display", "inline-block");
$(email).next().html("email is not valid");
$(email).next().css("color", "red");
}
});
// regular expressiong to check for email validity
function validateEmails() {
var emailtest = $("#email").val();
var reg = /^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
if (reg.test(emailtest)) {
return true;
} else {
$(email).css("border", "1px solid red");
$(email).next().css("display", "inline-block");
$(email).next().html("email is not valid");
$(email).next().css("color", "red");
return false;
}
}
// validatename
function validateName() {
if ($(name).val().length < 2) {
$(name).css("border", "1px solid red");
$(name).next().css("display", "inline-block");
return false;
} else {
$(name).css("border", "1px solid green");
$(name).next().css("display", "none");
return true;
}
}
// submit button code
$(form).submit(function (e) {
let modal = $(".modals");
e.preventDefault();
if (validateEmails() && validateName && validatePassAndCpass()) {
// console.log("valid");
modal.css("display", "block");
} else {
// console.log(validateName());
// console.log(validateEmails());
// console.log(validatePassAndCpass());
// console.log("invalid");
validateName();
validatesPass();
validatescPass();
validateEmails();
validatePassAndCpass();
emptyEmail();
}
});
});