This does well in both examples:
$t="222-222-2222-122"; or $t="222-222-2222;
if(! preg_match('/^\d{3}-\d{3}-\d{4}(\-\d{3})?$/', $t))
But I cannot find how to make the last part (phone extension) matching any optional number of digits from 1 to 5 digits
As is since it is optional it works if not any number are entered but if any are entered it indeed calls for 3 or whatever is required between {}
How may I modify it to accept either 0 or any digits from 1 to 5 any digits