净RegularEx pressionValidator比正则表达式匹配类不同 [英] .Net RegularExpressionValidator matches differently than Regex class
问题描述
当我使用.NET RegularEx pressionsValidator控制验证前pression匹配确切的文本。当我说我的意思是,对于字符串我给它来验证,如果它从正则表达式模式偏离在所有的字符串不验证。
When I use the .Net RegularExpressionsValidator control the Validation expression matches EXACT text. When I say this I mean, for the string I give it to validate, if it deviates from the regex pattern at all the string does not validate.
例如:(([0-1] [0-9])|([2] [0-3]))([0-5] [0-9]) 00foo,bar23:00,foobar的
ex: (([0-1][0-9])|([2][0-3])):([0-5][0-9]) if given in the RegularExpressionsValidator control will only match strings like -> 12:00, 07:15, 23:59 but does not match strings 12:00foo, bar23:00, foobar.
现在,当我使用正则表达式类在后面的code,并给它同普通的前pression它匹配包含匹配和任何其他字符的所有字符串。
Now, when I use the Regex class in the code behind and give it the same regular expression it matches all strings that contain a match and any other characters.
例如:(使用同一个正前pression作为最后一个例子),如果我用正则表达式类以下字符串将匹配 - > 12:00,07:15,23: 59和12:00foo(包含一个匹配),bar23:00(包含一个匹配)
ex: (Using the same regular expression as the last example) if I use the Regex class the following strings will match -> 12:00, 07:15, 23:59 AND 12:00foo (contains a match), bar23:00 (contains a match).
还有一个原因是,他们的处理方式不同,是有办法模仿相同的行为RegularEx pressionValidator控制?
Is there a reason that they are treated differently and is there a way to mimic the same behavior as the RegularExpressionValidator control?
在此先感谢!
推荐答案
这是怎么回事的是,正则表达式验证正在处理您的字符串作为一行文本。它是隐式投入^和$匹配器在正则表达式的开头。
What's happening is that the regex validator is processing your string as a line of text. It is implicitly putting in the ^ and $ matchers at the beginning of the regex.
这等于是说:
^(([0-1][0-9])|([2][0-3])):([0-5][0-9])$
以上EX pression在正则表达式类
将产生相同的结果验证控制。
The above expression in the Regex Class
will produce the same result as the validator control.
这篇关于净RegularEx pressionValidator比正则表达式匹配类不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!