The regular expression ^((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}$
matches strings of the form XXX-XXX-XXXX
and XXX-XXXX
(am I missing out something?).
It doesn't, however, match (XXX) XXX-XXXX
and (XXX) XXX-XXX-XXXX
as well (which I need it to match).
Can you help me fix it so that it matches the formats
XXX-XXX-XXXX
,
XXX-XXXX
,
(XXX) XXX-XXXX
,
(XXX) XXX-XXXX
without causing it to match other string formats which I don't want?