asp.netmaskededitextenderreg-expressionvalidator

RegularExpressionValidator with 4 or 5 characters


A new requirement for me is to expand error validation on an input field. Currently it looks like this:

<asp:TextBox ID="TextBox_Tracking_BenOpt" 
     runat="server" 
     AutoPostBack="True" 
     Height="16px" Width="115px" 
     OnTextChanged="TBBenOpt_OnLeave"></asp:TextBox>
<AJAXControls:MaskedEditExtender ID="MeeBenOpt" 
     runat="server" 
     Mask="CCCCC" 
     MaskType="None" 
     TargetControlID="TextBox_Tracking_BenOpt" 
     PromptCharacter="_" InputDirection="LeftToRight" />
<asp:RegularExpressionValidator 
     Display="Dynamic" 
     ControlToValidate="TextBox_Tracking_BenOpt" 
     ID="RevBenOpt" 
     ValidationExpression="^[0-9A-Z]{5,}$" 
     runat="server" 
     ErrorMessage="X" ForeColor="Red" 
     Font-Size="Large"></asp:RegularExpressionValidator>

(Yes, I know I didn't put proper breaks here, but I did this for readability for the SO community. In my actual code, it's all on one line.)

As you can see, the validator checks for a 5-character value and throws an error if it doesn't have one. So, how would/could I change this so that it will allow either 4 or 5 characters? Is this even possible?


Solution

  • Modify this and try again

    ValidationExpression = "^[0-9A-Z]{4,5}$"