required field validator allows blank and

Dovberman
Dovberman used Ask the Experts™
on
A blank entry or zero length string is not caught by the RequiredFieldValidator.

How can I fix this?

Thanks,
<asp:RequiredFieldValidator 
        ID="ReqdMaxPrice" runat="server" 
        ErrorMessage="Maximum price not entered"
        ControlToValidate="txtMaxPrice" SetFocusOnError=true 
        EnableClientScript="False" InitialValue="1">&quot;*&quot;
    </asp:RequiredFieldValidator>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Please add this with the required Field validator, else you can add a Client Script to check whether the length of the value after triming is greater than zero.

<asp:RegularExpressionValidator id="RegularExpressionValidator" runat="server" ErrorMessage="Invalid number. Must be between 0 and 99." InitialValue="" Display="Dynamic" ControlToValidate="txtMaxPrice" ValidationExpression="^\d{1,2}$">Invalid number</asp:RegularExpressionValidator>

Open in new window

Commented:
As far as I know, you should not have the "InitialValue" property set. That is useful though if you want to validate a drop down list. Try to remove that and see what it does?

Author

Commented:
I am using the following regular expression validator to enforce entry of a decimal value xx.xx.

<asp:RegularExpressionValidator ID="valMaxPrice" runat="server"
        ErrorMessage="The Maximum Price needs to be numeric"
        ValidationExpression="^\d{0,2}(\.\d{1,2})?$"
        ControlToValidate="txtMaxPrice" SetFocusOnError=true >
    </asp:RegularExpressionValidator>

How can I modify this to prevent blanks?
Thanks,
Commented:

<asp:TextBox ID="txtMaxPrice" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Please enter price." ControlToValidate="txtMaxPrice"></asp:RequiredFieldValidator>
        <asp:RegularExpressionValidator ID="valMaxPrice" runat="server"
        ErrorMessage="The Maximum Price needs to be numeric"
        ValidationExpression="^\d{0,2}(\.\d{1,2})?$"
        ControlToValidate="txtMaxPrice" SetFocusOnError="true"  >
    </asp:RegularExpressionValidator>
        <asp:Button ID="Button1" runat="server" Text="Button" />

Open in new window

Author

Commented:
Thank you.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial