The regular expression ^((\\(\\d{3}\\) ?)|(\\d{3}-))?\\d{3}-\\d{4}$ matches strings of the form XXX-XXX-XXXX and XXX-XXXX (am I missin
^((\\(\\d{3}\\) ?)|(\\d{3}-))?\\d{3}-\\d{4}$
XXX-XXX-XXXX
XXX-XXXX
I think so this is what you are looking for,
/^((((([0-9]{3})-)|((([0-9]{3}))\s))([0-9]{3})-([0-9]{4}))|(([0-9]{3})-([0-9]{4})))$/
It will work for below patterns XXX-XXX-XXXX, XXX-XXXX, (XXX) XXX-XXXX