-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
157 lines (138 loc) · 3.9 KB
/
index.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
function isEmpty(para) {
const element = $(`#${para}`).val();
if (element == "") {
$("#warn").removeClass("d-none");
$("#warn").html(`Please fill the ${para}`);
$(`#${para}`).addClass("error");
$(`#${para}`).focus();
setTimeout(() => {
$("#warn").addClass("d-none");
}, 3000);
return false;
// break;
} else $(`#${para}`).removeClass("error");
}
const regName = /^[A-Za-z\s]+$/;
const emailValid = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
const phoneno = /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/;
const passwordFormat =
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/gm;
const arrayOfId = [
"address",
"contactNumber",
"confirmPwd",
"pwd",
"emailId",
"fullName",
];
const isNameValid = () => {
const fullName = $("#fullName").val();
if (!fullName.match(regName)) {
$("#warn").removeClass("d-none");
$("#warn").html(`Please enter a valid Name`);
$(`#fullName`).addClass("error");
$(`#fullName`).focus();
setTimeout(() => {
$("#warn").addClass("d-none");
}, 3000);
return false;
} else {
$(`#fullName`).removeClass("error");
}
};
const isPhoneValid = () => {
const contactNumber = $("#contactNumber").val();
if (!contactNumber.match(phoneno)) {
$("#warn").removeClass("d-none");
$("#warn").html(`Please enter a valid Contact Number`);
$(`#contactNumber`).addClass("error");
$(`#contactNumber`).focus();
setTimeout(() => {
$("#warn").addClass("d-none");
}, 3000);
return false;
} else {
$(`#contactNumber`).removeClass("error");
}
};
const isPasswordValid = () => {
const pwd = $("#pwd").val();
const confirmPwd = $("#confirmPwd").val();
if (!pwd.match(passwordFormat)) {
$("#warn").removeClass("d-none");
$("#warn").html(
`Password Should be Minimum eight characters, at least one uppercase letter, one lowercase letter, one number and one special character`
);
$(`#pwd`).addClass("error");
$(`#pwd`).focus();
setTimeout(() => {
$("#warn").addClass("d-none");
}, 3000);
return false;
} else {
$(`#pwd`).removeClass("error");
}
if (confirmPwd != pwd) {
$("#warn").removeClass("d-none");
$("#warn").html(`Confirm password doesn't match with Password`);
$(`#confirmPwd`).addClass("error");
$(`#confirmPwd`).focus();
setTimeout(() => {
$("#warn").addClass("d-none");
}, 3000);
return false;
} else {
$(`#confirmPwd`).removeClass("error");
}
};
const isEmailValid = () => {
const emailId = $("#emailId").val();
if (!emailId.match(emailValid)) {
$("#warn").removeClass("d-none");
$("#warn").html(`Please enter a valid email`);
$(`#emailId`).addClass("error");
$(`#emailId`).focus();
setTimeout(() => {
$("#warn").addClass("d-none");
}, 3000);
return false;
} else {
$(`#emailId`).removeClass("error");
}
};
// $('#fullName').keypress(isNameValid());
// $('#emailId').keypress(isEmailValid());
// $('#contactNumber').keypress(isPhoneValid());
// $('#pwd').keypress(isPasswordValid());
// $('#confirmPwd').keypress(isPasswordValid());
$("#submitButton").click(function () {
const regName = /^[A-Za-z\s]+$/;
const emailValid = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
const phoneno = /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/;
const passwordFormat =
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/gm;
if (
$("#emailId").val().match(emailValid) &&
$("#pwd").val().match(passwordFormat) &&
$("#confirmPwd").val() == $("#pwd").val() &&
$("#contactNumber").val().match(phoneno) &&
$("#fullName").val().match(regName) &&
$("address").val() != ""
) {
$("#signIn").removeClass("d-none");
$("#signIn").html("Form Submiited");
$("#signIn").css("fontWeight", "bolder");
setTimeout(() => {
$("#signIn").addClass("d-none");
}, 5000);
const regForm = $("#regForm");
} else {
for (let i = 0; i < arrayOfId.length; i++) {
isEmpty(arrayOfId[i]);
}
isPhoneValid();
isPasswordValid();
isEmailValid();
isNameValid();
}
});