Only numbers, a digit can be decimal (regular expression)

in my web application, I want to check that the user can enter only numbers, and the number can be integer or decimal, as I can write a regular expression for this. help me thank you

+4
source share
2 answers

You can use RegularExpressionValidator , and here is the expression Validation ValidationExpression="[0-9]*\.?[0-9]*"

Finally it will look ...

  <asp:RegularExpressionValidator ID="rgx" ControlToValidate="txtControl" runat="server" ErrorMessage="*" Display="Dynamic" ValidationExpression="[0-9]*\.?[0-9]*"></asp:RegularExpressionValidator> 
+17
source

Have you considered using RangeValidation as an alternative? This may not meet your requirements, but it gives you the opportunity to specify the type of input that you expect, which can be any of a string, integer, double, date or currency. Choosing a double or exchange rate and setting the MinimumValue and MaximumValue properties to values ​​that match your input requirements can do the trick.

+2
source

Source: https://habr.com/ru/post/1299515/


All Articles