C#正则表达式来验证电话号码 [英] C# Regex to validate phone number

查看:157
本文介绍了C#正则表达式来验证电话号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这将是巨大的,如果有人可以帮助我的电话号码的正则表达式。以下是条件:

It would be great if someone could help me with a Regex for phone numbers. Following are the conditions:


  • 如果+存在,那么它应该是第一个字符

  • 允许的字符是数字()的空间 - 而

  • 6个号码,最大12

  • (,)和空间最小可以串进来任何地方

  • - 不应该是第一个和最后一个字符,不应+后立即出现,如果+存在

  • If + is present, then it should be the first character
  • Allowed characters are numbers ( ) space - and .
  • Minimum of 6 numbers and max 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

  • + 1 703 335 65123

  • 34565464

  • 001(703)332-6261

  • +1703.338.6512

  • + 934-83227359

  • (111)123-4567

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

感谢

推荐答案

与尝试<?/ p>

Try with:

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



然而,它不处理计数

However it does not handle number counting

这篇关于C#正则表达式来验证电话号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆