This didn't answer my question.
Possible inputs (may have whitespace):
- full number: (XXX) XXX-XXXX
- full number: XXX/XXX-XXXX
- full number: XXXXXXXXXX
- no area code: XXX-XXXX
- no area code: XXXXXXX
- extension only: XXXX
So if you regex it for digits only s/[^\d]//g
, you'll hopefully get 1 of 3 options:
- XXXXXXXXXX
- XXXXXXX
- XXXX
Which I would like to format as so:
- XXX/XXX-XXXX
- XXX-XXXX
- XXXX
Is the best way to do this to do if
statements based on the length? Or is there a more one-liner approach?