难道RegularEx pressionValidator使用其他的味道比正则表达式? [英] Does RegularExpressionValidator use other flavor than Regex?
问题描述
我想要做的preliminary检查,如果输入的字符串看起来像车辆识别代号(VIN)一>。我知道它是由17个字母和数字,但字母I,O和Q里面没有车辆允许的,所以我用这个普通的前pression:
I want to do preliminary check if entered string looks like Vehicle Identification Number (VIN). I know what it consists of 17 letters and digits, but letters I, O and Q are not allowed inside VIN, so I use this regular expression:
^[0-9A-Z-[IOQ]]{17}$
现在,如果我检查像1G1FP22PXS2100001一个字符串RegularEx pressionValidator失败了,但的CustomValidator这个OnServerValidate事件处理程序
Now if I check a string like 1G1FP22PXS2100001 with RegularExpressionValidator it fails, but CustomValidator with this OnServerValidate event handler
Regex r = new Regex("^[0-9A-Z-[IOQ]]{17}$");
args.IsValid = r.IsMatch(TextBox1.Text);
效果很好。
works well.
实验证明什么RegularEx pressionValidator不支持字符类减法< /一>,但正则表达式类一样。
Experiments show what RegularExpressionValidator doesn't support Character Class Subtraction, but Regex class does.
现在我很感兴趣,为什么这两个.NET类使用不同的正则表达式的口味?难道是记录somethere?
Now I am interested why do these two .NET classes use different regex flavors? Is it documented somethere?
推荐答案
在RegularEx pressionValidator还支持使用JavaScript,在JavaScript的正则表达式引擎用于客户端验证。您所看到的不同之处在于JavaScript和.NET的正则表达式实现之间的区别。 您可以禁用客户端验证,从而迫使验证使用.NET正则表达式引擎,回来后,额外的代价。
The RegularExpressionValidator also supports client-side validation using JavaScript, where the JavaScript Regex engine is used. The difference you see is the difference between the JavaScript and the .NET regex implementation. You can disable client-side validation and thus force the validator to use the .NET regex engine, at the price of the additional post-back.
这篇关于难道RegularEx pressionValidator使用其他的味道比正则表达式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!