开发者

ASP.NET Regular Expression Validator

I need a Regular Expression that can validate an exact 3 character(alpha only) code but also a blank field to set as the validation expression of a ASP.NET RegEx validator control. I am c开发者_运维知识库urrently using ^[a-zA-Z]{3}$ and this works out well to match the code but of course doesn't match a blank. I have been looking at using something like this: ^(?:|)[a-zA-Z]{3}$


If your intention is to allow blank fields, then use the original pattern of ^[a-zA-Z]{3}$ since the RegularExpressionValidator doesn't validate blank fields. It will allow them.

However, if you want to prevent blank entries then you'll need to add a RequiredFieldValidator to validate the same control, in addition to the RegularExpressionValidator.


Have you tried using (^$)|(^[a-zA-Z]{3}$)?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜