Phone number validator not working!

Step 35 and step 36 glitching, even when it’s working. Here’s the code:

const userInput = document.getElementById('user-input');
const checkBtn = document.getElementById('check-btn');
const resultsDiv = document.getElementById('results-div');
const theclear = document.getElementById("clear-btn");

const pf1= /1 \([1-9][1-9][1-9]\) [1-9][1-9][1-9]-[1-9][1-9][1-9][1-9]/;
const pf2= /\([1-9][1-9][1-9]\)[1-9][1-9][1-9]-[1-9][1-9][1-9][1-9]/
const pf3= /[1-9][1-9][1-9]-[1-9][1-9][1-9]-[1-9][1-9][1-9][1-9]/;
const pf4= /[1-9][1-9][1-9][1-9][1-9][1-9][1-9][1-9][1-9][1-9]/;
const pf5= /1 [1-9][1-9][1-9] [1-9][1-9][1-9] [1-9][1-9][1-9][1-9]/;
const pf6= / 1\([1-9][1-9][1-9]\)[1-9][1-9][1-9]-[1-9][1-9][1-9][1-9]/;
const pf7= /1 [1-9][1-9][1-9]-[1-9][1-9][1-9]-[1-9][1-9][1-9][1-9]/;
const wrong= /^(?!1$)\d{2,} [1-9][1-9][1-9]-[1-9][1-9][1-9]-[1-9][1-9][1-9][1-9]/;
const wrong2= /\([1-9][1-9][1-9]-[1-9][1-9][1-9]-[1-9][1-9][1-9][1-9]/;
const wrong3= /^(?!1$)\d{1,}\([1-9][1-9][1-9]\)[1-9][1-9][1-9]-[1-9][1-9][1-9][1-9]/;
theclear.addEventListener("click", function(){
  resultsDiv.innerHTML = "";
});
checkBtn.addEventListener("click",function(){
  if(userInput.value===""){
    alert("Please provide a phone number");
  }else if(userInput.value.charAt(0)==="-"){
    resultsDiv.innerHTML="Invalid US number: "+userInput.value;
  }else if(pf1.test(userInput.value)||pf2.test(userInput.value)||pf3.test(userInput.value)||pf4.test(userInput.value)||pf5.test(userInput.value)||pf6.test(userInput.value)||pf7.test(userInput.value)){
    if(wrong.test(userInput.value)||wrong2.test(userInput.value)||wrong3.test(userInput.value)){
      resultsDiv.innerHTML="Invalid US number: "+userInput.value;
    }else{
      resultsDiv.innerHTML="Valid US number: "+ userInput.value;
    }
  }else{
    resultsDiv.innerHTML="Invalid US number: "+userInput.value;
  }
});
// Valids: 1 555-555-5555, 
//1(555) 555-5555, 5555555555, 555-555-5555, 
//(555)-555-5555, 1(555)555-5555
//, 1 555 555 5555, 1 456 789 4444.

can you share your html and a link to the project please?


I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

One of your “wrong” regex is matching on a valid number. Check them against the number from the failing test output. Copy and paste the number from the test so you get it with the correct spaces, or lack there of.