Number validation in required field validator

后端 未结 7 1421
挽巷
挽巷 2021-02-05 08:08

Is it possible to put Number validation in required field validator in asp.net text box?

相关标签:
7条回答
  • 2021-02-05 08:40

    You should use the CompareValidator, for example:

    <asp:TextBox ID="txt" runat="server />
    <asp:CompareValidator ID="cv" runat="server" ControlToValidate="txt" Type="Integer"
       Operator="DataTypeCheck" ErrorMessage="Value must be an integer!" />
    

    This is the most natural choice if you want a simple data type check. Otherwise if you want to verify a range use the RangeValidator suggestions. If you need a certain pattern use the RegularExpressionValidator.

    Note that you'll want to add a RequiredFieldValidator as well since some validators will allow blank entries.

    0 讨论(0)
提交回复
热议问题