Javascript phone number validation

后端 未结 7 822
感动是毒
感动是毒 2020-12-01 18:51

I need to validate a phone number in javascript. The requirements are:

they should be 10 digits, no comma, no dashes, just the numbers, and not the

7条回答
  •  旧时难觅i
    2020-12-01 19:17

    Code to except only numbers braces and dashes

    function DoValidatePhone() {
        var frm = document.forms['editMemberForm'];                
        var stripped = frm.contact.value;
        var isGoodMatch = stripped.match(/^[0-9\s(-)]*$/);
        if (!isGoodMatch) {
            alert("The Emergency Contact number contains invalid characters." + stripped);
            return false;
        }
    }
    

提交回复
热议问题