印度手机号码的正则表达式

ans*_*hul 45 regex

我希望正常表达印度手机号码,包括10位数字.
应该匹配的数字从9或8或7开始.

例如:

9882223456
8976785768
7986576783
Run Code Online (Sandbox Code Playgroud)

它不应与从1到6或0开始的数字匹配.

eld*_*his 111

^[789]\d{9}$ 应该做的伎俩.

^     #Match the beginning of the string
[789] #Match a 7, 8 or 9
\d    #Match a digit (0-9 and anything else that is a "digit" in the regex engine)
{9}   #Repeat the previous "\d" 9 times (9 digits)
$     #Match the end of the string
Run Code Online (Sandbox Code Playgroud)

UPDATE

印度的一些电信运营商推出了新的手机号码系列,从数字6开始.

用于此用途:

^[6-9]\d{9}$
Run Code Online (Sandbox Code Playgroud)

  • @RavinderPayal这个正则表达式用`^`和`$`锚定,以确保它只匹配整个字符串.它不匹配超过10个字符的字符串,也不匹配更少的字符串.无论您正在使用哪种正则表达式引擎或方法都会导致它.[这是你在Rubular中的字符串](http://rubular.com/r/NBvMyEO9AA) - 它只匹配10个字符. (3认同)

web*_*ebx 39

^(?:(?:\+|0{0,2})91(\s*[\-]\s*)?|[0]?)?[789]\d{9}$
Run Code Online (Sandbox Code Playgroud)

嗨,这是印度本地手机号验证和印度国际的正则表达式.

从9,8,7开始,你也可以添加更多.

你可以使用https://regex101.com/进行测试

有效数字是.

9883443344
09883443344
919883443344
0919883443344
+919883443344
+ 91-9883443344
0091-9883443344
+91 -9883443344
+ 91- 9883443344
+91 - 9883443344
0091 - 9883443344


Mar*_*age 7

重申其他答案以及有关数字的其他信息:

new Regex("^[7-9][0-9]{9}$")
Run Code Online (Sandbox Code Playgroud)

将匹配使用罗马数字编写的电话号码.

new Regex(@"^[7-9]\d{9}$", RegexOptions.ECMAScript)
Run Code Online (Sandbox Code Playgroud)

将与之前的正则表达式匹配.RegexOptions.ECMAScript指定何时\d匹配任何罗马数字.

new Regex(@"^[7-9]\d{9}$")
Run Code Online (Sandbox Code Playgroud)

将匹配使用任何数字写入最后9位数的电话号码.

区别在于前两个模式只匹配电话号码,9123456789而第三个模式也匹配电话号码9?????????.

因此,您可以使用\d匹配原生数字.但是,如果要将原始数字的匹配限制为仅限某些(例如7-9),则需要执行其他步骤.对于旁遮普(印度)能够匹配??????????你可以这样做:

CultureInfo.GetCultureInfo("pa-IN").NumberFormat.NativeDigits.Skip(7).Take(3)
Run Code Online (Sandbox Code Playgroud)

这将返回7-9的原始数字.然后,您可以将它们连接在一起,形成数字7-9的"文化感知"正则表达式.


小智 7

这对我有用

^(?:(?:\+|0{0,2})91(\s*[\ -]\s*)?|[0]?)?[789]\d{9}|(\d[ -]?){10}\d$
Run Code Online (Sandbox Code Playgroud)

有效场景:

+91-9883443344
9883443344
09883443344
919883443344
0919883443344
+919883443344
+91-9883443344
0091-9883443344
+91 -9883443344
+91- 9883443344
+91 - 9883443344
0091 - 9883443344
7856128945
9998564723
022-24130000
080 25478965
0416-2565478
08172-268032
04512-895612
02162-240000
+91 9883443344
022-24141414
Run Code Online (Sandbox Code Playgroud)

无效场景:

WAQU9876567892
ABCD9876541212
0226-895623124
6589451235
0924645236
0222-895612
098-8956124
022-2413184
Run Code Online (Sandbox Code Playgroud)


abh*_*yan 5

你可以用这个

/^(?:(?:\+|0{0,2})91(\s*|[\-])?|[0]?)?([6789]\d{2}([ -]?)\d{3}([ -]?)\d{4})$/
Run Code Online (Sandbox Code Playgroud)

有效条目:

6856438922
7856128945
8945562713
9998564723
+91-9883443344
09883443344
919883443344
0919883443344
+919883443344
+91-9883443344
0091-9883443344
+91 9883443344
+91-785-612-8945
+91 999 856 4723
Run Code Online (Sandbox Code Playgroud)

无效条目:

WAQU9876567892
ABCD9876541212
0226-895623124
0924645236
0222-895612
098-8956124
022-2413184
Run Code Online (Sandbox Code Playgroud)

https://regex101.com/验证它

  • 电话号码与国际代码一起存储是很常见的,因此这种模式可以更好地服务于表单中的剪切和粘贴工作。 (2认同)

小智 5

我在我的项目中使用了这个正则表达式,效果很好。

pattern="[6-9]{1}[0-9]{9}"
Run Code Online (Sandbox Code Playgroud)