Tell us what’s happening:
My code doesn’t pass the 35th test. I don’t know why.
Your code so far
<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<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: script.js */
const userInput = document.getElementById("user-input");
const checkBtn = document.getElementById("check-btn");
const clearBtn = document.getElementById("clear-btn");
const resultsDiv = document.getElementById("results-div");
let regexArr = [
/^1 \d{3}-\d{3}-\d{4}$/,
/^1 \(\d{3}\) \d{3}-\d{4}$/,
/^1\(\d{3}\)\d{3}-\d{4}$/,
/^1 \d{3} \d{3} \d{4}$/,
/^\d{10}$/,
/^\d{3}-\d{3}-\d{4}$/,
/^\(\d{3}\)\d{3}-\d{4}$/
];
clearBtn.onclick = ()=>{
userInput.value="";
resultsDiv.innerHTML="";
}
checkBtn.onclick = ()=>{
const input = userInput.value.trim();
if (!input)
{
alert("Please provide a phone number");
return;
}
if (regexArr.some((regex)=>regex.test(input)))
{
resultsDiv.innerHTML = `Valid US number: ${input}`;
userInput.value = "";
}
else
{
resultsDiv.innerHTML = `Invalid US number: ${input}`;
userInput.value = "";
}
}
/* file: styles.css */
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Challenge Information:
Build a Telephone Number Validator Project - Build a Telephone Number Validator