English 中文(简体)
多国电离层
原标题:Phone Number Validation in Multiple Countries [closed]

在不同国家,我很难找到对电话号码的验证模式,没有什么时间来尝试和书写我自己的字,希望能够提供帮助。

我已经检查了像凯雷卜这样的通常来源,这样,任何人都能够帮助与他们中的任何一个亲爱。

I need a separate phone number validation expression for each of the following:

  • Germany
  • US
  • Australia
  • New Zealand
  • Canada
  • Asia
  • France
问题回答

格式是here

编写该条例并非微不足道,但如果你具体指明规则,则不会有困难。

Instead of making an elaborate regular expression to match how you think your visitor will input their phone number, try a different approach. Take the phone number input and strip out the symbols. Then the regular expression can be simple and just check for 10 numeric digits (US number, for example). Then if you need to save the phone number in a consistent format, build that format off of the 10 digits.

这一例子通过寻找10位数字验证了美国的电话号码。

protected bool IsValidPhone(string strPhoneInput)
{
// Remove symbols (dash, space and parentheses, etc.)
string strPhone = Regex.Replace(strPhoneInput, @”[- ()*!]“, String.Empty);

// Check for exactly 10 numbers left over
Regex regTenDigits = new Regex(@”^d{10}$”); 
Match matTenDigits = regTenDigits.Match(strPhone);

return matTenDigits.Success;
}

电话号码是电话号码,你想要证实这一点吗?

Here

没有一个像亚洲这样的国家,这个大陆有几个国家。

几乎不可能有一个涵盖所有国家的定期表述。

I d go with [0-9+][0-9() ]* -- this simply allows any digit to start (or the "+" character), then any combination of digits or parentheses or spaces.


总的说来,任何进一步的验证都不会真正得到很大利用。 如果该网页的用户希望通过电话联系,他们就会打上有效的电话号码——如果不是的话,他们就会打赢。

执行正确电话号码和消除最简单的误导的更好办法是要求进入twice<>em>,用户至少可以检查号码!





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!