美文网首页
1,手机号格式化

1,手机号格式化

作者: 前端开发菜鸟 | 来源:发表于2019-09-27 16:49 被阅读0次

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    </head>
    <body>

    </body>
    <script>
    var reg = /[+-\s]/g,
    mobileReg = /^(13|15|18)\d{9}$/,
    res = [], tempStr;

    var phones = [ ' +86 12345678910 ', ' 8613898765421', '135-1234-5678', '+8615145698763', '+86 151-4569-8763']

    for (var i = 0; i < phones.length;i++) {
    tempStr = phones[i].trim().replace(reg, '').slice(-11);
    if (mobileReg.test(tempStr)) {
    res.push(tempStr)
    }
    }

    console.log(res);
    // ["13898765421", "13512345678", "15145698763", "15145698763"]
    转载
    https://segmentfault.com/q/1010000002804317

    </script>
    </html>

    相关文章

      网友评论

          本文标题:1,手机号格式化

          本文链接:https://www.haomeiwen.com/subject/bmdauctx.html