Regular Expression for Phone Number

前端 未结 1 393
余生分开走
余生分开走 2020-12-07 04:55

I need a Javascript RegEx through which I can validate phone number. RegEx should handle following criteria

  1. It should only consist of numbers ( ) + and -
相关标签:
1条回答
  • 2020-12-07 05:45

    Try this:

    function valid_phone_number(ph) {
      var regex = /^(?!([^-]*-){5})(\+\d+)?\s*(\(\d+\))?[- \d]+$/gi;
      return regex.test(ph);
    }
    

    I'm new to regular expressions, so please be nice. :-)

    0 讨论(0)
提交回复
热议问题