-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
37 lines (30 loc) · 1 KB
/
script.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
let menu = document.querySelector('#menu-btn');
let navbar = document.querySelector('.navbar');
menu.onclick = () =>{
menu.classList.toggle('fa-times');
navbar.classList.toggle('active');
}
window.onscroll = () =>{
menu.classList.remove('fa-times');
navbar.classList.remove('active');
}
function formValidate(){
const fname=document.getElementById('fname').value;
const inEmail=document.getElementById('inEmail').value;
const phone=document.getElementById('phone').value;
function validateEmail(email){
const pattern=/\S+@\S+\.\S+/;
return pattern.test(email);
}
function validatePhone(phoneNumber){
const pattern=/^\+?([0-9]{2})\)?[-. ]?([0-9]{4})[-. ]?([0-9]{4})$/;
return pattern.test(phoneNumber);
}
if(fname===""){
alert("Enter your name.");
}else if(!validatePhone(phone)){
alert("Enter your phone number.")
}else if(!validateEmail(inEmail)){
alert("Enter a valid email id example : 'mymail@gmail.com'")
}
};