I need help creating a regular expression that validates a US telephone number with or without extension. It needs to require an area code enclosed in parentheses and separated by a space, require a dash(-) between the prefix and the number, and allow an extension up to 4 digits(ex. x1234). Some matches and non-matches are provided below.
Match (789) 555-1234
Match (849) 555-1234 x1234
Match (484) 555-8764 x1
Non-Match 789-555-7894
Non-Match 7895551234
Non-Match (546) 555-1354 x12345
Non-Match (345) 555-8794 x
Non-Match 756 468 4657
I've searched the net a found a few that claim to meet my requirements but under testing they all have some loophole that matches something it should not. Any help would be greatly appreciated.