MY #100 DAYS OF CODE CHALLENGE JOURNEY-DAY 7
Problem: US Number Validator
Problem Definition: The purpose of the program is to collect an input and check if it obeys the USA standard way of writing a phone number.
Algorithm
I created a regular expression inside the function.
I tested if it matches the user input then returned true if does otherwise returned false.
JavaScript Code
function number numberValidator(num) {
return /^(1\s?)?((\d{3})|\d{3})[\s-]?(\d{3})[\s-]?(\d{4})$/.test(num);
};
numberValidator(555-557-7778);