Regex : Phone number starting with 06 or 07

被刻印的时光 ゝ 提交于 2020-07-30 14:15:57

问题


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);
}

I would like to check phone number starting with 06 or 07.

Ex :

06 01010101 : true

07 01240101 : true

00 04343000 : false


回答1:


var reg = new RegExp('^((06)|(07))[0-9]{8}$', 'i');



回答2:


I guess it's a simple case:

^0[67][0-9]{8}$



回答3:


'^0(6|7) [0-9]{8}$'

Or if you mean you want the numbers without a space:

'^0(6|7)[0-9]{8}$'

Check out some excellent regex tutorials here and here.




回答4:


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.




回答5:


Try it /^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$/ and for more details check below links help you how validate your phone and defined specific format

http://www.zparacha.com/phone_number_regex/

http://dzone.com/snippets/regular-expression-validate



来源:https://stackoverflow.com/questions/18060259/regex-phone-number-starting-with-06-or-07

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!