我需要有关正则表达式,ASP.NET的帮助吗? [英] I need help in regex expression , ASP.NET ?

查看:56
本文介绍了我需要有关正则表达式,ASP.NET的帮助吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有用于ZIP /邮政编码的asp RegularExpressionValidator,但我有问题我想在最后允许空间,我不希望显示错误时最后一个字符空间<<



exp



立陶宛99999如果我在9之后点击空格将是错误的邮政编码?

可以处理它?



我的尝试:



i have asp RegularExpressionValidator i do for ZIP/Postal code , but i have problem i want allow for space at the end , i dont want show error when last char space <<

exp

Lithuania 99999 if i click in space after 9 will be wrong zip code ?
can handle it?

What I have tried:

case "Luxembourg": result = @"\d{4}";
                   break;

               case "Latvia": result = @"\d{4}";
                   break;

               case "Monaco": result = @"\d{5}";
                   break;

               case "Malta": result = @"[A-Z]{3}[ ]?\d{2,4}";
                   break;

               case "Netherlands": result = @"\d{4}[ ]?[A-Z]{2}";
                   break;

               case "Norway": result = @"\d{4}";
                   break;

               case "Poland": result = @"\d{5}";
                   break;

推荐答案

尝试将可选空格添加到结束:

Try adding optional whitespace to the end:
\d{4}\s*

但是...将一个正则表达式限制为整个输入通过添加开始和结束标记:

But...It's a good idea to restrict teh regex to "the whole input" by adding start and end markers:

^\d{4}\s*


没有它们,基本正则表达式将匹配

Without them, the "basic" regex will match

Hello1234567890Bye!

作为两个有效的邮政编码:

as two valid postcodes:

1234
5678


不是解决方案,但应该仍然很有趣。

以下是RegEx文档的链接:

perlre - perldoc.perl.org [ ^ ]

这是指向帮助构建RegEx并调试它们的工具:

.N ET Regex Tester - Regex Storm [ ^ ]

Expresso正则表达式工具 [ ^ ]

这个显示RegEx是一个很好的图表,它对于理解RegEx的作用非常有帮助:

Debuggex:在线可视正则表达式测试程序。 JavaScript,Python和PCRE。 [ ^ ]
Not a solution, but should be still interesting.
Here is a link to RegEx documentation:
perlre - perldoc.perl.org[^]
Here is links to tools to help build RegEx and debug them:
.NET Regex Tester - Regex Storm[^]
Expresso Regular Expression Tool[^]
This one show you the RegEx as a nice graph which is really helpful to understand what is doing a RegEx:
Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.[^]


这篇关于我需要有关正则表达式,ASP.NET的帮助吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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