Tell us what’s happening:
So according to the instruction this was suppose to work but instead it gives me an error maybe my regex is wrong or what please help?
Your code so far
<!-- file: index.html -->
<!DOCTYPE html>
<html>
<head>
<title>Your Title Here</title>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<h1>Hello, World!</h1>
<input type="text" id="user-input">
<button id="check-btn">Check</button>
<button id="clear-btn">Clear</button>
<div id="results-div"></div>
<script src="./script.js"></script>
</body>
</html>
/* file: styles.css */
/* file: script.js */
const input = document.getElementById("user");
const check = document.getElementById("check-btn");
const clear = document.getElementById("clear-btn");
const results = document.getElementById("results-div");
check.addEventListener("click", () =>{
const regex = /^(1\s?)?(\(\d{3}\)|\d{3})([\s-]?)\d{3}([\s-]?)\d{4}$/
if (!input){
alert("Please provide a phone number")
}else if(regex.test(input)){
results.innerHTML = `Valid US number: ${input}`
}else{
results.innerHTML = `Invalid US number: ${input}`
}
});
clear.addEventListener("click", () =>{
results.innerHTML = null;
})
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36
Challenge Information:
Build a Telephone Number Validator Project - Build a Telephone Number Validator