Regular expression to match US phone numbers

前端 未结 5 1293
臣服心动
臣服心动 2020-12-22 04:31

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

5条回答
  •  半阙折子戏
    2020-12-22 04:47

    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

提交回复
热议问题