Question
I am trying to validate my form on my website. and if it is not corret then to let the users know what is wrong
I am trying to validate my form on my website. and if it is not corret then to let the users know what is wrong with what they are entering.
This is my form.
This is the HTML
This is my javascript
const form = document.getElementById("myForm");
form.addEventListener("submit",(e)=>{
//e.preventDefault();
let name = document.getElementById("name").value;
let email = document.getElementById("emailf").value;
let phone = document.getElementById("tel").value;
let company = document.getElementById("company").value;
let regex = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if(name == "") {
alert("Name must be filled out");
}
if(email == "") {
alert("Email must be filled out");
}
if(phone == "") {
alert("Phone must be filled out");
}
if(company == "") {
alert("Company must be filled out");
}
if (email== regex){
alert("This matches!")
}
})
I am trying to check the email, and phone number. what am i doing wrong? and how can i fix this? i want to alert if there if something is wrong. thank you!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started