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

Tell us what’s happening:

I just finished writing my phone validator code but it’s funny it’s not working on FCC but on other platforms and tools it’s working somebody help.

Your code so far

<!-- file: index.html -->
<input id="user-input"></input>
<button id="check-btn">Check</button>
<button id="clear-btn">Clear</button>
<div id="results-div"></div>
/* file: styles.css */

/* file: script.js */
const userInput = document.getElementById('user-input');
const checkBtn = document.getElementById('check-btn');
const clearBtn = document.getElementById('clear-btn');
const results = document.getElementById('results-div');

const tenDigits = /^(:?\d{10})$/;
const hyphSpace = /^(:?\d{3}[-\s]?\d{3}[-\s]?\d{4})$/;
const parenths = /^(:?\(\d{3}\)\s?\d{3}[-\s]?\d{4})$/;
const begOne = /^1\s?\(?\d{3}\)?[-\s]?\d{3}[-\s]?\d{4}$/;
const phonelist = [tenDigits, hyphSpace, parenths, begOne]

const isValid = (numb) => phonelist.some(regex => regex.test(numb));

const checkInput = () => {
  if(userInput.value === ''){
    alert("Please provide a phone number");
    return;
  }
  results.textContent = isValid(userInput.value)
    ? `Valid US number: ${userInput.value}`
    : `Invalid US number: ${userInput.value}`;
  userInput.value = "";
};

const clearResults = () => {
  results.textContent = ""
};

checkBtn.addEventListener('click', checkInput);
clearBtn.addEventListener('click', clearResults);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36

Challenge Information:

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

how are you linking the other files to your html file?

Got it. Coding & bugs :joy: I almost cried :joy: :joy: :joy:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.