MY #100 DAYS OF CODE CHALLENGE JOURNEY-DAY 7

in #coding5 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.27
TRX 0.11
JST 0.030
BTC 67808.48
ETH 3831.14
USDT 1.00
SBD 3.55