Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Only digits, the digit may be decimal (regular expression)

in my web application i want to validate that user can enter only digits and the digit may be a integer or decimal how can i write the regular expression for this. help me thank you

like image 688
Surya sasidhar Avatar asked Dec 02 '22 06:12

Surya sasidhar


2 Answers

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

Finally it will be look like...

 <asp:RegularExpressionValidator ID="rgx" ControlToValidate="txtControl" runat="server"
      ErrorMessage="*" Display="Dynamic" ValidationExpression="[0-9]*\.?[0-9]*"></asp:RegularExpressionValidator>
like image 193
Muhammad Akhtar Avatar answered Dec 04 '22 01:12

Muhammad Akhtar


Have you considered using a RangeValidation as an alternative? This may not meet your requirements but it does give you the ability to specify the input type you are expecting which could be any one of string, integer, double, date or currency. Choosing double or currency and setting the MinimumValue and MaximumValue properties to values which meet your input requirements may do the trick.

like image 27
Andy Rose Avatar answered Dec 04 '22 01:12

Andy Rose