views:

346

answers:

2

Hi,

Shouldn't this regex validator make sure the user enters something in the textbox? For some reason an empty textbox passes through.

<asp:RegularExpressionValidator ID="revNumericValidator" runat="server" ValidationExpression="^\d+$"
                    ControlToValidate="tb1" ErrorMessage="Please enter blah (must be a number)." />
+6  A: 

Validators by convention don't validate empty text. If you want to require a value, you have to also add a RequiredFieldValidator.

MSDN says

Validation succeeds if the input control is empty. If a value is required for the associated input control, use a RequiredFieldValidator control in addition to the RegularExpressionValidator control.

bdukes
A: 

I am not sure why this is the case, but with the ASP.NET validator controls I have always had to combine a RegEx validator with a Required field validator, as the RegEx one only seems to fire if there is text included in the field.

Mitchel Sellers