开发者

Regular expression for Indian landline Phone numbers

开发者 https://www.devze.com 2023-01-27 02:30 出处:网络
Indian landline phone numbers are in one of the开发者_运维问答 following format. 080 25478965 0416-2565478

Indian landline phone numbers are in one of the开发者_运维问答 following format.

080 25478965
0416-2565478
08172-268032

Whats the simplest Regex to accommodate all these. The space between the city code and the phone number can be a whitespace or a "-". It would be great if the regex can accommodate the case without the separator between the city code and the phone number.


For these three formats exactly:

^\d{3}([ -]\d\d|\d[ -]\d|\d\d[ -])\d{6}$

Another, more liberal option, is to allow a space or a dash after each digit (except maybe the last):

^(\d[ -]?){10}\d$


I'd probably just use /^(\d+[ \-]+\d+)$/ if you don't need to verify the number of digits etc. If you'd like to get both parts separated: /^(\d+)[ \-]+(\d+)$/


^[\d]{3,4}[\-\s]*[\d]{6,7}$

This would match [3-4 digits][zero to many dashes and whitespaces][6-7 digits]

0

精彩评论

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