easy +10 pts

Validate phone number

Use regex patterns to verify if a phone number is valid.

Write a function `is_valid_phone_number(s: str) -> bool` that returns `True` if the input string `s` is a valid US-style phone number, and `False` otherwise. A valid phone number must follow one of these exact formats: - `(XXX) XXX-XXXX` (with parentheses, a space after the closing parenthesis, and a hyphen) - `XXX-XXX-XXXX` (hyphens between groups) - `XXX.XXX.XXXX` (dots between groups) - `+1 XXX XXX XXXX` (with country code, spaces between groups) Each `X` is a digit from 0-9. No other characters (like letters, extra spaces, or parentheses in other positions) are allowed. Leading/trailing spaces in the input are allowed and should be ignored. Use the `re` module to implement your check.

Constraints

- The input string length is between 0 and 50. - The input contains only printable ASCII characters. - Your function should be efficient; the `re.fullmatch` or similar approach is sufficient.

Example

```python
>>> is_valid_phone_number("(123) 456-7890")
True
>>> is_valid_phone_number("123-456-7890")
True
>>> is_valid_phone_number("123.456.7890")
True
>>> is_valid_phone_number("+1 123 456 7890")
True
>>> is_valid_phone_number("1234567890")
False
>>> is_valid_phone_number("(123)456-7890")
False
```
10 points ~15 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Use `re.fullmatch` to match the entire string after stripping whitespace.
Combine all four patterns into one regex with alternation (`|`).
Remember to escape special characters like parentheses and dots in the regex.
Use `\d` to match any digit.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.