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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1151216/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 09:27:03  来源:igfitidea点击:

Regular expression for Indian mobile phone numbers?

c#regex

提问by knowledgehunter

I'm looking for a regular expression that will match text given the following requirements:

我正在寻找一个符合以下要求的正则表达式:

  • contains only 10 digits (only numbers)
  • starts with 9.
  • 仅包含 10 位数字(仅数字)
  • 从 9 开始。

These examples should match:

这些示例应该匹配:

  • 9999999999
  • 9876543210
  • 9999999999
  • 9876543210

These examples should not match:

这些示例不应匹配:

  • 999999999
  • 1234567890
  • 8912456789
  • qwe3456&ert
  • 999999999
  • 1234567890
  • 8912456789
  • qwe3456&ert

It is basically for Indian mobile numbers.

它基本上适用于印度手机号码。

Please provide examples, I have already searched Google and those answers provide over-validation.

请提供示例,我已经搜索过谷歌,这些答案提供了过度验证。

采纳答案by Andrew Hare

Try something like this:

尝试这样的事情:

^9\d{9}$

回答by Erix

9{1}\d{9}

or without predefined \d

或没有预定义 \d

9{1}[0-9]{9}

回答by paxdiablo

I always prefer the REs that can be used on any engine (so no fancy "\d"things):

我总是更喜欢可以在任何引擎上使用的 RE(所以没有花哨的"\d"东西):

^9[0-9]{9}$

or, in a crunch,

或者,在紧要关头,

^9[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$

if the RE engine doesn't even have "{}".

如果 RE 引擎甚至没有"{}".

Yes, I know the C# engine can do both "\d"and "{}"but that's not always the case.

是的,我知道 C# 引擎可以做到这两者"\d""{}"但情况并非总是如此。

回答by arnabmitra

^9[0-9]{9}$

^9[0-9]{9}$

回答by arnabmitra

Try this it is tested

试试这个它被测试

^([9]{1})([0-9]{9})$

回答by Suvro

Try this it is tested

试试这个它被测试

^([7-9]{1})([0-9]{9})$

回答by user4849702

^([1-9]{1})([0-9]{9})$                 

Try This 10 digit Mobile No validation = ^([1-9]{1})([0-9]{9})$ This Expression is very useful for Indian Mobile Nos .This Expression doesn't allow first digit Zero(example:0123456789).

试试这个 10 位手机号 没有验证 = ^([1-9]{1})([0-9]{9})$ 这个表达式对于印度手机号非常有用。这个表达式不允许第一个数字零(例如:0123456789)。

回答by user4849702

Chk this out....... Expression

Chk 这个....... 表达

^((\+){0,1}91(\s){0,1}(\-){0,1}(\s){0,1}){0,1}9[0-9](\s){0,1}(\-){0,1}(\s){0,1}[1-9]{1}[0-9]{7}$

Description : This expression is to validate indian mobile nos

描述:此表达式用于验证印度移动号码

Matches :

火柴 :

9836193498
+919836193498
9745622222

9836193498
+919836193498
9745622222

Non-Matches :

不匹配:

+9197456222222
8745622222
9836193481

+9197456222222
8745622222
9836193481

回答by d-coder

try this

尝试这个

^(((\+?\(91\))|0|((00|\+)?91))-?)?[7-9]\d{9}$

回答by Fatal Exception

Well,I have written this regular expression to validate Indian mobile number.Basically number in India starts with 7-9 excluding country code( +91 ) and (0).This regex will check mobile number pattern including country code. for example

好吧,我写了这个正则表达式来验证印度手机号码。基本上印度的号码以 7-9 开头,不包括国家代码(+91)和(0)。这个正则表达式将检查包括国家代码在内的手机号码模式。例如

  • +91-8978989089
  • 09090898978
  • 9909876767
  • 0091-999897678 are valid number
  • +91-8978989089
  • 09090898978
  • 9909876767
  • 0091-999897678为有效号码

regex is:

正则表达式是:

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

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

you can check/test your input here regex validation

您可以在此处检查/测试您的输入正则表达式验证