开发者

Regex : Matching phone numbers starting with NNN and having 10 numbers

开发者 https://www.devze.com 2022-12-29 12:46 出处:网络
I need to match phone numbers that : start with 010 or 012 or 016 or 019 Consist of 10 numbers exactly Can you please help me on h开发者_开发知识库ow to match numbers using PHP and regex?return pr

I need to match phone numbers that :

  • start with 010 or 012 or 016 or 019

  • Consist of 10 numbers exactly

Can you please help me on h开发者_开发知识库ow to match numbers using PHP and regex?


return preg_match('/^01[0269]\\d{7}$/', $theStringToTest);

This will match 0, 1, one of (0, 2, 6, 9), and then any 7 numbers (3+7==10). The ^ means start of string and $ means end of string.


I think I'd use ^01[0269][0-9]{7}$


Use this Regex

/\b(010|012|016|019)[0-9]{7}\b/g
0

精彩评论

暂无评论...
验证码 换一张
取 消