Participate in Codex, Test Your Skills & Win BIG

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

123 456 7890
(123) 456-7890

Sample output

(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
  • Hint 1
  • Solution Approach
  • Complete Solution


Click here to start solving coding interview questions