Validating Phone Numbers Using Javascript

前端 未结 9 2210
刺人心
刺人心 2021-01-06 00:41

I\'m working on a web form with several fields and a submit button. When the button is clicked, I have to verify that the required text boxes have been filled in and that th

9条回答
  •  难免孤独
    2021-01-06 01:17

    function telephoneCheck(str) {
      var a = /^(1\s|1|)?((\(\d{3}\))|\d{3})(\-|\s)?(\d{3})(\-|\s)?(\d{4})$/.test(str);
      alert(a);
    }
    telephoneCheck("(555) 555-5555");

    Where str could be any of these formats: 555-555-5555 (555)555-5555 (555) 555-5555 555 555 5555 5555555555 1 555 555 5555

提交回复
热议问题