i wrote code for this task,
but it doesn’t work. only first 4 Task ware success.
and i can not find more where is falsh.
could you please check it .

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Telephone Number Validator</title>
    <link rel="stylesheet" href="styles.css">
<h1>Telephone Number Validator</h1>
<p>Enter a Phone Number:</p>
<input  id="user-input" type="text"></input>
<div id="results-div"></div>
<button id="check-btn" type="submit">check</button>
<button id="clear-btn" type="reset">clear</button>
<script src="script.js"></script>
const userInput = document.getElementById("user-Input");
const checkBtn = document.getElementById("check-btn");
const clearBtn = document.getElementById("clear-btn");
const result = document.getElementById("results-div");

function message(){
const getNumber = userInput.value;
const regex = /^(1\s?)?(\(\d{3}\)|\d{3})[\s\-]?\d{3}[\s\-]?\d{4}$/;

if (!getNumber) {
        alert("Please provide a phone number");
  result.innerHTML = `<p>Valid US number: ${getNumber}</p>`
}else{result.innerHTML = `<p>Invalid US number: ${getNumber}</p>`

const clear = () =>{
  result.innerText = ''};

clearBtn.addEventListener("click", clear);
checkBtn.addEventListener("click", message);

Did you see the error message in your console ?

1 Like

thank you so much. i didn’t know how to use console,
now i could find error and finish this work.
thank you so much

1 Like