Build a Telephone Number Validator Project - Build a Telephone Number Validator

Tell us what’s happening:

Bonjour tout le monde ici se son les numero valide seulement qui marche . Parcontre meme si je rentre un numero Invalide il me retourne Valid US number. J’ai besoin d’aide .

Your code so far

<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">
  <head>
  <meta charset="utf-8">
  <title> Built Telephone Number</title>
  <link rel="stylesheet" href="styles.css">
  </head>
  <body>
    <h1>Telephone Number Validator </h1>
    <input  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.querySelector("#user-input")
const check      = document.querySelector("#check-btn")
const  clear     = document.querySelector("#clear-btn")
const results    = document.querySelector("#results-div")

check.addEventListener("click", () =>{
  const regexCheck = /^(\d{1}?:(\-|\s{1})?\(\d{3}\)(\-|\s{1})\d{3}(\-|\s{1})\d{4})?|(\d{10})?$/
  if(userInput.value === ""){
    alert("Please provide a phone number")
  }else if(userInput.value !==""){
      const verifIf = regexCheck
     if(verifIf.test(userInput.value)){
    results.innerHTML =`Valid Us number: ${userInput.value}`
    }else if(!verifIf.test(userInput.value)){
      results.innerHTML =`Invalid Us number: ${userInput.value}`
    }
  }
})
clear.addEventListener("click", () =>{
  results.textContent = ""
})
/* 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/126.0.0.0 Safari/537.36

Challenge Information:

Build a Telephone Number Validator Project - Build a Telephone Number Validator

I can’t find anything that comes up as invalid. Either your regex is seriously mal-formed or your code is not even checking it.

Valid Us number: kklhjg

I’ve confirmed your code IS checking against the regex :white_check_mark:

Your regex seems malformed. Test your regex here:
https://regex101.com/

Everything comes back as matching an empty string. Literally anything you type matches successfully. You need to rebuild it from scratch.

You could also do this with multiple if statements and a few regex’s, it doesn’t need to be all in 1 regex.