/
index.html
225 lines (178 loc) · 8.75 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Todo List App built with HTML, CSS and Javascript">
<meta name="Author" content="devInTheNorth">
<meta name="robots" content="index, follow">
<title>Sign Up</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
</header>
<section>
<form id="RegForm">
<fieldset aria-label="Registration Form" aria-describedby="#h1">
<h1 id="h1" > Sign Up Form </h1>
<label for="txtFName">First Name:</label>
<p>
<input type="text" name="txtFName" placeholder="First Name" id="txtFName" required pattern="^[a-zA-Z]{2,25}$"></p>
<label for="txtLName">Last Name:</label>
<p>
<input type="text" name="txtLName" placeholder="Last Name" id="txtLName" required pattern="^[a-zA-Z]{2,25}$"></p>
<label for="txtMail">Email Address:</label>
<p>
<input type="email" name="txtMail" placeholder="Email Address" id="txtMail" aria-required="true" required pattern="^.+@.+\..{2,4}$"></p>
<label for="txtPhone">Phone Number [Int'l Format] :</label>
<p><input placeholder="+234" type="text" name="txtPhone" id="txtPhone" required pattern="^\+234[0-9]{10}$"></p>
<label for="txtPword">Password [8 to 20 characters] </label>
<p>
<input type="password" name="txtPword" minlength="8" maxlength="20" id="txtPword" aria-required="true" required pattern="^(.){8,20}$"></p>
<label for="txtCPword">Confirm Password</label>
<p>
<input type="password" name="txtCPword" id="txtCPword" required pattern="^(.){8,20}$"></p>
<div class="progress"><meter value="0" max="100" id="progress"></meter> <span class="progress"></span>
</div>
<!-- <p> <input type="submit" id="btnSub" class="btn" value="Submit"> </p> -->
<p> <button type="submit" id="btnSub" class="btn"> Submit </button> </p>
</fieldset>
</form>
</section>
<footer> Made with <span class="love" > ❤️ </span> by <a href="https://www.github.com/devInTheNorth">devInTheNorth</a> </footer>
<script src="helper.js"></script>
<script>
let progressBar = document.querySelector('#progress');
let validCtrls = new Array();
let isValidFName = false, isValidLName = false , isValidMail = false, isValidPhone = false, isValidPword = false, isConfirmedPword = false;
window.addEventListener('load', () => {
initPhone();
})
/* let a= document.querySelector('#txtFName').addEventListener('input blur', () =>{
if(a.value == 'a'){console.log('bnfndfn')} else{console.log('njandknfd')};
}) */
function validateTexts(){
let el = document.querySelectorAll(`input[type=text'], input[type=email'], input[type=password']`);
el.addEventListener('blur', () => {
})
}
function initPhone(){
let a= document.querySelector('#txtPhone');
a.addEventListener('focus', () =>{
if(a.value == ""){ a.value = "+234"; }
});
a.addEventListener('blur', () =>{
if(a.value == ""){ a.value = "+234"; }
});
}
function validateInput(Input_Element, booleanCtrl){
let a = document.querySelector(`#${Input_Element}`);
//let regex = new RegExp(Input_Element.getAttribute('pattern')); */
/* booleanCtrl = (regex.test(Input_Element.value))? true: false; */
if(a.checkValidity() == true ){
(a.className.includes('invalid'))? a.classList.replace('invalid', 'valid') : a.classList.add('valid') ;
if (! validCtrls.includes(a.id))
{
validCtrls.push(a.id);
progressBar.value += 18;
reportProgress();
}
}
else if(a.checkValidity() == false){
(a.className.includes('valid'))? a.classList.replace('valid', 'invalid'): a.classList.add('invalid') ;
//a.insertAdjacentHTML('afterEnd', `<span class='checked'> ✅ </span>`);
// progressBar.value += (booleanCtrl == false)? 0: -10;
// booleanCtrl = false;
if (validCtrls.includes(a.id))
{
validCtrls.pop(a.id);
progressBar.value += (progressBar.value == 0)? 0: -18 ;
reportProgress();
}
}
}
function reportProgress(){
document.querySelector('span.progress').textContent = progressBar.value + "%";
}
function findEl(Element_ID){
return document.querySelector(Element_ID);
}
function addClass(Element_ID, new_class){
return document.querySelector(Element_ID).classList.add(new_class);
}
function replaceClass( Element_ID, old_class, new_class){
return document.querySelector(Element_ID).classList.replace( old_class, new_class);
}
function makeGreen(Input_Element){
findEl(`#${Input_Element}`).style.border = '2px solid rgb(59, 235, 88)';
findEl(`#${Input_Element}`).style.borderBottom = '3px solid rgb(59, 235, 88)';
}
function confirmPassWord(){
let pword = document.querySelector('#txtPword');
let cpword = document.querySelector('#txtCPword');
if(pword.value == cpword.value && cpword.checkValidity() ){
(cpword.className.includes('invalid'))? cpword.classList.replace('invalid', 'valid') : cpword.classList.add('valid') ;
if (! validCtrls.includes(cpword.id))
{
validCtrls.push(cpword.id);
progressBar.value += 10;
reportProgress();
}
}
else if(pword.value != cpword.value ){
(cpword.className.includes('valid'))? cpword.classList.replace('valid', 'invalid'): cpword.classList.add('invalid') ;
// progressBar.value += (booleanCtrl == false)? 0: -10;
// booleanCtrl = false;
if (validCtrls.includes(cpword.id))
{
validCtrls.pop(cpword.id);
progressBar.value += (progressBar.value == 0)? 0: -10 ;
reportProgress();
}
}
}
/* VALIDATE ALL INPUT TEXTS */
document.querySelector('#txtFName').addEventListener('blur', function() {
validateInput(this.id, isValidFName);
})
document.querySelector('#txtLName').addEventListener('blur', function() {
validateInput(this.id, isValidLName);
})
document.querySelector('#txtMail').addEventListener('blur', function() {
validateInput(this.id, isValidMail);
})
document.querySelector('#txtPhone').addEventListener('blur', function() {
validateInput(this.id, isValidPhone);
})
document.querySelector('#txtPword').addEventListener('blur', function() {
validateInput(this.id, isValidPword);
})
document.querySelector('#txtCPword').addEventListener('blur', function() {
/* (findEl('#txtPword').value == findEl('#txtCPword').value)? () =>{
if((findEl('#txtPword')).className.includes('valid')){replaceClass(`#${this.id}`, 'invalid', 'valid');}
else{addClass(`#${this.id}`, 'valid');}
} : () => {
if((findEl('#txtPword')).className.includes('valid')){replaceClass(`#${this.id}`, 'valid', 'invalid');}
else{addClass(`#${this.id}`, 'invalid');}
}
*/
/* let pword = document.querySelector('#txtPword');
let cpword = document.querySelector('#txtCPword');
if(pword.value == cpword.value){
if(cpword.className.includes('invalid')){
// replaceClass(`#${this.id}`, 'invalid', 'valid');
cpword.className.replace('invalid', 'valid')
}
}
else{
if(cpword.className.includes('valid')){
// replaceClass(`#${this.id}`, 'invalid', 'valid');
cpword.className.replace('valid', 'invalid')
}
} */
confirmPassWord();
})
</script>
</body>
</html>