Zoya
Zoya

Reputation: 405

I want regular expression for validating decimal number and doesn't allow value 0.00

I'm uaing following regular expression for validating decimal or numeric (18,3) numbers, it does disallow users from entering more than 1 decimal points and all that

<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="Invalid" ControlToValidate="txtqty"  ValidationExpression="^[-+]?[0-9]*\.?[0-9]*([?[0-9]+)?$" ValidationGroup="save"></asp:RegularExpressionValidator>

but i also want to disallow users from entering any value equal to 0 like the following eg:

0.00, 0000.00, 00.0, 0...

Upvotes: 3

Views: 8030

Answers (4)

Zoya
Zoya

Reputation: 405

<asp:RangeValidator ID="RangeValidator1" runat="server" ErrorMessage="Invalid" ControlToValidate="txtqty" MaximumValue="99999" MinimumValue="1.0000" ValidationGroup="save"></asp:RangeValidator>      

range validator works

Upvotes: 0

user1465587
user1465587

Reputation:

"Use following regular expression:

^\d[1-9]*(\.\d+)|([0-9])$

it disallow values in following pattern:

00.00,0123.78 i.e value before decimal followed by 0

Upvotes: 1

Jupaol
Jupaol

Reputation: 21365

I think the problem is that you are using one validator to perform more than one task

Divide your problem:

  • Validate the format

  • Validate specific values

Use a simple CompareValidator in addition to your RegularExpressionValidator

<asp:CompareValidator ErrorMessage="Value must be grater than 0" ControlToValidate="TextBox1"
    runat="server" Operator="NotEqual" Type="Double" ValueToCompare="0" />

Upvotes: 2

Sanket R. Patil
Sanket R. Patil

Reputation: 311

You can used this

^([1-9][0-9]*\.[0-9]+)|([0-9]+)$

Upvotes: 0

Related Questions