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

Coin Marketplace

STEEM 0.25
TRX 0.20
JST 0.036
BTC 95982.42
ETH 3487.66
USDT 1.00
SBD 3.47