Answered by:
Numeric Values

Question
-
User-797751191 posted
Hi
I have below line and want that it should accept only Numeric Values >= 0
<div class="form-group col-md-4 has-error">
<label>Amount *</label>
<asp:TextBox ID="txtAmount" runat="server" class="form-control" placeholder="Enter Amount" ></asp:TextBox>
</div>Thanks
Sunday, June 23, 2019 1:53 PM
Answers
-
User288213138 posted
Hi jsshivalik,
You can use RegularExpressionValidator control to validate whether the value of an associated input control matches the pattern specified by a regular expression.
The code:
<div class="form-group col-md-4 has-error"> <label>Amount *</label> <asp:TextBox ID="txtAmount" runat="server" class="form-control" placeholder="Enter Amount"></asp:TextBox> <asp:RegularExpressionValidator ID="Regex1" runat="server" ValidationExpression="^([1-9]\d*(\.\d+)?|0)$" ErrorMessage="Please enter >=0 value." ControlToValidate="txtAmount" /> </div>
Best regards,
Sam
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, June 24, 2019 6:37 AM
All replies
-
User1120430333 posted
What you can do is write a little JavaScript function that takes the data from the control and validates that the data is all numeric data, do an Alert box, and set focus back to the control if not numeric. You would execute the function on the control's Onblur() event.
https://www.mkyong.com/javascript/check-if-variable-is-a-number-in-javascript/
Sunday, June 23, 2019 2:26 PM -
User475983607 posted
Hi
I have below line and want that it should accept only Numeric Values >= 0
<div class="form-group col-md-4 has-error">
<label>Amount *</label>
<asp:TextBox ID="txtAmount" runat="server" class="form-control" placeholder="Enter Amount" ></asp:TextBox>
</div>Thanks
This problem has been solved long ago using standard Validation Server Controls found in the Visual Studio Toolbox View.
Sunday, June 23, 2019 5:33 PM -
User288213138 posted
Hi jsshivalik,
You can use RegularExpressionValidator control to validate whether the value of an associated input control matches the pattern specified by a regular expression.
The code:
<div class="form-group col-md-4 has-error"> <label>Amount *</label> <asp:TextBox ID="txtAmount" runat="server" class="form-control" placeholder="Enter Amount"></asp:TextBox> <asp:RegularExpressionValidator ID="Regex1" runat="server" ValidationExpression="^([1-9]\d*(\.\d+)?|0)$" ErrorMessage="Please enter >=0 value." ControlToValidate="txtAmount" /> </div>
Best regards,
Sam
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, June 24, 2019 6:37 AM