Valid phone number

Given a text file input that contains list of phone numbers (one per line).

Write a bash script to print all valid phone numbers.You may assume that a valid phone number must appear in one of the following two formats:

  • (xxx) xxx-xxxx
  • xxx-xxx-xxxx

You may also assume each line in the text file must not contain leading or trailing white spaces.

Sample Input

987-123-4567
123 456 7890
(123) 456-7890

Sample output

987-123-4567
(123) 456-7890
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Valid phone number on Interview Code Editor
Sign Up
to access hints and editorial solutions for Valid phone number

Discussion


Loading...
Click here to start solving coding interview questions