This is my code for the phone validator I just cant seem to get past more then a few numbers and I tried as much as I could think of any suggestions please.
const userInput = document.getElementById("user-input");
const checkBtn = document.getElementById("check-btn");
const clearBtn = document.getElementById("clear-btn");
const resultsDiv = document.getElementById("results-div");
checkBtn.addEventListener('click', function() {
const inputValue = userInput.value.trim();
if (inputValue === "") {
alert("Please provide a phone number");
return;
}
const regex = /^((1\s){0,1}\d{3}-\d{3}-\d{4}|((1\s){0,1}|1)\(\d{3}\)\s{0,1}\d{3}-\d{4}|(1\s){0,1}\d{3}\s\d{3}\s\d{4}|\d{10})$/;
if (regex.test(inputValue)) {
resultsDiv.textContent = "Valid US number: " + inputValue;
} else {
resultsDiv.textContent = "Invalid US number: " + inputValue;
}
});
clearBtn.addEventListener('click', function() {
userInput.value = "";
resultsDiv.textContent = "";
});
});