Your task is to write a program or function that checks if a string is a valid phone number.
Given a string (or list of characters/codepoints) input, you will output a truthy value if the input is a valid phone number. If it is not, output a falsey value. An input string is considered a valid phone number for this challenge if it meets all of these criteria:
- It contains ten digits, which are grouped like this:
- The strings separating the digit groups must be the same
- The first and last characters must be part of the phone number (i.e. must not be part of a separator)
111-222-3333 truthy 123-456-7890 truthy (number groups can contain different numbers) 1112223333 truthy (can have 0 length separators) 111022203333 falsey (has more than 10 numbers) 111ABC222ABC3333 truthy (can have length>1 separators) 111-222_3333 falsey (non-matching separators) 111-22-23333 falsey (missing digit in middle group) 111--222--33333 falsey (extra digit in last group) -111-222-3333 falsey (first character is not part of number) 111-222-3333a falsey (last character is not part of number) aaa-aaa-aaaa falsey (not enough numbers) 11-2222-3333 falsey (wrong separator location) 111-1-222-1-3333 falsey (too many numbers)
This is a code golf challenge, shortest answer per language wins.