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 currently 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}$
I need a Regular Expression that can validate an exact 3 character(alpha only) code
Share
If your intention is to allow blank fields, then use the original pattern of
^[a-zA-Z]{3}$since theRegularExpressionValidatordoesn’t validate blank fields. It will allow them.However, if you want to prevent blank entries then you’ll need to add a
RequiredFieldValidatorto validate the same control, in addition to theRegularExpressionValidator.