The Telephone Number Validator is a web project made with HTML, CSS, and JavaScript. It uses a regular expression (regex) to check whether a user’s input matches valid US phone number formats, including different separators like spaces, dashes, or parentheses.
The app runs validation with addEventListener(), gets the input using getElementById(), and uses regex.test() to display whether the phone number is valid or not.
- Validates a user’s US telephone number format.
- Supports multiple input styles (spaces, dashes, parentheses, or no separators).
- Ensures the area code is required.
- If a country code is included, it must be 1 (US) to be accepted.
- Shows a clear success/error message based on the validation result.
- HTML
- CSS
- JavaScript:
- regex to define the allowed US phone formats
- regex.test() to check if the entered number matches the pattern
- addEventListener() to run validation on submit/button click
- getElementById() to read the input value and update the result text
- Open
index.htmlin your browser.