Regex : Phone number starting with 06 or 07

后端 未结 5 1720
北海茫月
北海茫月 2021-01-26 22:02

I have this function which works only for 10 digits.

function telValide( tel )
{
    var reg = new RegExp(\'^[0-9]{10}$\', \'i\');
    return reg.test(tel);
}
<         


        
5条回答
  •  太阳男子
    2021-01-26 22:48

    The easiest pattern would probably be

    ^0[67]\d{8}$
    

    i.e.

    • 0
    • 6 or 7
    • a digit
    • repeated exactly eight times

    That assumes that your white space is merely for emphasis.

    You could also be fancy and use a lookahead

    ^(?=0[67])\d{10}+$
    

    This isn't really adding much expect complexity however.

提交回复
热议问题