English 中文(简体)
为允许()和空间而对电话号码进行验证,但我使用的电话号码不允许进入。
原标题:Validation for Phone Number to allow () and space, but regex I am using is not allowing to enter those.
  string Phno=txt_EditPhno.Text;
        bool check = false;
        Regex regexObj = new Regex(@"^(?:(?:+?1s*(?:[.-]s*)?)?(?:(s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])s*)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))s*(?:[.-]s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})s*(?:[.-]s*)?([0-9]{4})(?:s*(?:#|x.?|ext.?|extension)s*(d+))?$");
        if ((String.IsNullOrEmpty(Phno))||(regexObj.IsMatch(Phno)))
        {}

我经常使用这一表述,允许电话号码允许,空间,(......)但不允许上述任何标志,是经常使用错误的表述,还是我以错误的方式这样做。

问题回答

The RegExstring You listed is working original:

System.Text.RegularExpressions.Regex regexObj = new System.Text.RegularExpressions.Regex(@"^(?:(?:+?1s*(?:[.-]s*)?)?(?:(s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])s*)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))s*(?:[.-]s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})s*(?:[.-]s*)?([0-9]{4})(?:s*(?:#|x.?|ext.?|extension)s*(d+))?$");
regexObj.IsMatch("(555)-867-5309")
true
regexObj.IsMatch("+15558675309")
true
regexObj.IsMatch("+1.555.867.5309")
true
regexObj.IsMatch("+15558675309ext12345")
true
regexObj.IsMatch("+15558675309x12345")
true

你们的法典中的错误必须是其他地方的。 你们总是能够使用RegExLib.com等工具,以测试你的登记。

采用稍有不同的做法,对你们也是有益的...... 在获得电话号码信息之前,我先采用某种方法,包括提取所需信息并重新定位,但你可能有不符合这一解决办法的要求,但我要建议这样做。

Using this match expression:

(?i)^D*1?D*([2-9])D*(d)D*(d)D*(d)D*(d)D*(d)D*(d)D*(d)D*(d)D*(d)[^x]*?s*(?:(?:e?(x)(?:.|t.?|tension)?)D*(d+))?.*$

改为:

($1$2$3) $4$5$6-$7$8$9$10 $12$13

你们应当能够改革这些投入:

Input                         Output
----------------------------- --------------------------------
"1323-456-7890 540"           "(323) 456-7890 "
"8648217634"                  "(864) 821-7634 "
"453453453322"                "(453) 453-4533 "
"@404-327-4532"               "(404) 327-4532 "
"172830923423456"             "(728) 309-2342 "
"17283092342x3456"            "(728) 309-2342 x3456"
"jh345gjk26k65g3245"          "(345) 266-5324 "
"jh3g24235h2g3j5h3x245324"    "(324) 235-2353 x245324"
"12345678925x14"              "(234) 567-8925 x14"
"+1 (322)485-9321"            "(322) 485-9321 "
"804.555.1234"                "(804) 555-1234 "

我恳请你不要说最有效率的表述,但低效的格言不是。 a 案文篇幅较短的问题,特别是在有知识和少量照料的情况下。

打破 par语:

(?i)^D*1?D*                      # mode=ignore case; optional "1" in the beginning
([2-9])D*(d)D*(d)D*           # three digits* with anything in between
(d)D*(d)D*(d)D*              # three more digits with anything in between
(d)D*(d)D*(d)D*(d)[^x]*?    # four more digits with anything in between
s*                                # optional whitespace
(?:(?:e?(x)(?:.|t.?|tension)?)   # extension indicator (see below)
D*(d+))?                         # optional anything before a series of digits
.*$                                # and anything else to the end of the string"

三位数不能从0或1位开始。 扩展指标可以是x,ex,xt,ext。 (所有时间可在末尾)extension,或xtension。 (期限不能结束)。

如书面所述,延期(数字,即)必须是一系列连续的编号(但通常都是,正如你所说的话)

The idea is to use the regex engine to pull out the first 10 digits (excluding "0" and "1", because domestic U.S. telephone numbers do not start with those (except as a switch, which is not needed or always needed, and is not dependent upon the destination phone, but the phone you re typing it into. It will then try to pull out anything up to an x , and capture the x , along with the first contiguous string of digits after that.

它允许在输入格式方面采取相当宽容的态度,同时排除有害数据或元数据,然后制作一个一贯设计的电话号码(一些电话经常受到许多层次的赞赏)。





相关问题
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!

热门标签