MY #100 DAYS OF CODE CHALLENGE JOURNEY-DAY 7

in #coding6 years ago

IMG_20190129_204424.jpg

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

  1. I created a regular expression inside the function.

  2. 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);