RegularExpressionValidator不能设置IgnoreCase选项的原因
RegularExpressionValidator没有忽略字母大小写选项,是微软懒惰吗?
控件RegularExpressionValidator并没有提供设置忽略字母大小写的选项,我们不能使用IgnoreCase项来让系统帮我们忽略字母大小写。是什么原因造成的呢?
看见有人是这样解释的:
If your control does both client-side and server-side validation, the
regex must use a subset of regular expression syntax that both
JScript and .Net can execute. In this case, to make a regex ignore
case it is necessary to use a character class construct like [a-zA-Z]
to match both upper and lower case characters.
大意是说由于客户端JavaScript和服务器端.Net程序对正则表达式执行的差异,导致没有办法写出能够兼容两者又能够忽略字母大小写的正则表达式。
想起来是有一定的道理。不过是不是可以通过设置一个属性给RegularExpressionValidator,动态的判断是服务器端执行还是客户端执行。如果是客户端执行,就通过程序修改正则表达式,让它能在js中正常运行呢?
实际上,有些设计者为了达到这个目的,就通过撰写js在客户端修改RegularExpressValidator中的正则表达式。因此这个功能的缺陷,可以说是微软的懒惰吗?
参考链接:http://www.velocityreviews.com/forums/t79327-regularexpressionvalidator-doesnt-ignore-case.html