Is the phone number valid?

Phone numbers in the United States typically consist of 11 digits:
  • 1-digit country code
  • 3-digit area code
  • 3-digit central office or exchange code
  • 4-digit subscriber number
A valid example can be: +1 (555) 555-1234.
So, the phone number should start with a +1, followed by a space and then 3 digits enclosed in parentheses. The last 7 digits are separated by a hyphen after the 3 digits.
Given a phone number print, The phone is valid if the phone is valid, and Invalid number otherwise.
+1 (555) 555-1234
The phone is valid
+1 (5a5) 555-1234
Invalid number
+1 (55) 555-1234
Invalid number


Time limit: 2 seconds

Memory limit: 512 MB

Output limit: 1 MB

To check your solution you need to sign in
Sign in to continue