-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidations.js
More file actions
65 lines (53 loc) · 1.63 KB
/
validations.js
File metadata and controls
65 lines (53 loc) · 1.63 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
//designing code for data validations
//const f=document.forms[0]; or
const frm=document.querySelector("#frm1");
/*attach Event
frm.onsubmit=function(){
code
} or */
frm.addEventListener("Submit",checkData);
//data validation
function checkData(f)//this method returns form tag Object
{
//fullname checking
const fnaa=document.querySelector("#fna").value;
const fnaaexp=/^[a-zA-Z]*$/;
if(fnaaexp.test(fnaa)===false || fna==="")
{
document.querySelector("#errfna").innerHTML=`plz enter valid name`;
f.preventDefault();//browser dont submit my form
}
else{
document.querySelector("#errfna").innerHTML="";
}
//phone num checking
const ph=document.querySelector("#phone").value;
const phexp=/^[6-9]\d{9} $/; //[6-9]->starting first digit b/w 6 to 9 and \d{9}->remaining 9 digits any digits
if(phexp.test(ph)===false)
{
document.querySelector("#errph").innerHTML=`enter a valid phone number`;
f.preventDefault();
}else{
document.querySelector("#errph").innerHTML="";
}
//pincode checking
const pc=document.querySelector("#pin").value;
const pcexp=/^\d{6} $/;
if(pcexp.test(pc)===false)
{
document.querySelector("#errpc").innerHTML=`enter a valid pin code`;
f.preventDefault();
}else{
document.querySelector("#errpc").innerHTML="";
}
//Password checking
const pw=document.querySelector("#pwd").value;
const pwexp=/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@#$%&*]).{8,20}$/;
if(pcexp.test(pw)===false)
{
document.querySelector("#errpwd").innerHTML=`Password should contains atleast 1 lower,upper, digits & symbol`;
f.preventDefault();
}else{
document.querySelector("#errpwd").innerHTML="";
}
}