import re

pattern = r'^\d{3}(?:[\-+](?:\d{4}(?:[\-+](?:\d{2})?)?)?)?$'

expected_pass = ['123-1234-12', '123-1234-', '123-1234', '123-', '123']
for string in expected_pass:
    string_match = re.match(pattern, string)
    print('expected pass', string_match)

expected_fail = ['123-123412', '1231234-12', '123--12']
for string in expected_fail:
    string_match = re.match(pattern, string)
    print('expected fail', string_match)

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: