skip to Main Content

Javascript if statement is executing on false condition

const resultsDiv = document.getElementById('results'); const value = '2555-555-5555'; const regex = /(1s?)?(d{3}|(d{3}))[-s]?d{3}[-s]?d{4}/; //I found this is an incorrect regex if (regex.test(value)) { console.log(regex.test(value)); //is false resultsDiv.querySelector("p").textContent = `Valid US number: ${value}`; } else { resultsDiv.querySelector("p").textContent = `Invalid US number: ${value}`;…

VIEW QUESTION
Back To Top
Search