简体   繁体   English

C#Regex验证电话号码

[英]C# Regex to validate phone number

It would be great if someone could help me with a Regex for phone numbers. 如果有人可以帮我使用正则表达式来获取电话号码,那就太好了。 Following are the conditions: 以下是条件:

  • If + is present, then it should be the first character 如果+存在,那么它应该是第一个字符
  • Allowed characters are numbers ( ) space - and . 允许的字符是数字()空格 - 和。
  • Minimum of 6 numbers and max 12 最少6个数字,最多12个
  • ( , ) and space can come anywhere in the string (,)和空格可以出现在字符串中的任何位置
  • - shouldn't be the first and last character and shouldn't appear immediately after +, if + is present. - 不应该是第一个和最后一个字符,如果+存在,则不应该在+之后立即出现。

Here are some valid numbers: 以下是一些有效数字:

  • +93483227359 93483227359
  • +1 703 335 65123 +1 703 335 65123
  • 34565464 34565464
  • 001 (703) 332-6261 001(703)332-6261
  • +1703.338.6512 +1703.338.6512
  • +934-83227359 + 934-83227359
  • (111)123-4567 (111)123-4567
  • 111-123-4567 111-123-4567

Thanks in advance 提前致谢

Try with: 试试:

^\+?(\d[\d-. ]+)?(\([\d-. ]+\))?[\d-. ]+\d$

However it does not handle number counting 但它不处理数字计数

不完全是你的问题的答案,但对于那些需要使用电话号码的人来说,谷歌的libphonenumber有一个.NET端口: libphonenumber-csharp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM