Javascript Regular Expression for International Phone Number

前端 未结 4 1513
有刺的猬
有刺的猬 2021-02-06 17:05

The following regular expression isn\'t working for international phone numbers that can allow up to 15 digits:

^[a-zA-Z0-9-().\\s]{10,15}$

W

4条回答
  •  终归单人心
    2021-02-06 17:46

    You may find the following regex more useful, it basically first strips all valid special characters which an international phone number can contain (spaces, parens, +, -, ., ext) and then counts if there are at least 7 digits (minimum length for a valid local number).

    function isValidPhonenumber(value) {
        return (/^\d{7,}$/).test(value.replace(/[\s()+\-\.]|ext/gi, ''));
    }
    

提交回复
热议问题