Javascript Regex - What to use to validate a phone number?

后端 未结 6 676
你的背包
你的背包 2020-12-05 21:04

Could anyone tell me what RegEx would work to validate an international phone number including white space between the numbers and also allowing for these chars: - ( )

6条回答
  •  孤城傲影
    2020-12-05 21:18

    Try this code

    HTML Code

    
    

    JS Code

    $("#phone").blur(function() {
      var regexp = /^[\s()+-]*([0-9][\s()+-]*){6,20}$/
      var no = $("#phone").val();
      if (!regexp.test(no) && no.length < 0) {
        alert("Wrong phone no");
      }
    });
    

提交回复
热议问题