-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathform.js
More file actions
48 lines (46 loc) · 1.07 KB
/
form.js
File metadata and controls
48 lines (46 loc) · 1.07 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
console.log("working");
var ht = document.getElementsByClassName("helptext");
function displayht(i){
ht[i].style.display="block";
}
function displayhtoff(i){
ht[i].style.display="none";
}
const input_fields = {
fname: /^([a-zA-Z]+)$/i,
lname: /^([a-zA-Z]+)$/i,
uname: /^([a-zA-Z\d-_\.]+)$/,
phone: /^\d{10}$/,
email: /^([a-zA-Z\d.-]+)@([a-z\d-]+)\.([a-z]{2,8})(\.[a-z]{2,8})?$/,
pword: /^[#\w@_-]{8}$/
}
const validate = (field, regex) => {
regex.test(field.value) ? field.className = 'valid' : field.className = 'invalid';
}
const keys = document.querySelectorAll('input');
keys.forEach(item => item.addEventListener(
'keyup', e => {
validate(e.target, input_fields[e.target.attributes.name.value])
}
));
function check(){
var count=0;
keys.forEach(item => {
if(item.className=="invalid"){
count=count+1;
item.focus();
}
});
keys.forEach(item => {
if(item.value==""){
count=count+1;
item.focus();
}
});
if(count!=0){
window.alert("invalid entry :(");
}
else{
window.alert("You are a part of family now ;)")
}
}