Link to home
Start Free TrialLog in
Avatar of zimmer9
zimmer9Flag for United States of America

asked on

How would you modify the following validation expression in ASP.NET to allow for thousands separators and value must be > 0.00?

How would you modify the following validation expression in ASP.NET  

^(\d){1,18}(\.\d{1,2})?$

to require a decimal point and ONLY 2 decimal places after the decimal point?

max value:           99,999,999,999,999.99

The value should be > 0.00
Avatar of John Gates, CISSP, CDPSE
John Gates, CISSP, CDPSE
Flag of United States of America image

^[0-9]{1,15}(\.[0-9]{1,2})?$
That is different than your original statement....

99,999,999,999,999.99

and you have 6.845.88
But you deleted what you posted LOL.  Did the expression work for you?
Avatar of zimmer9

ASKER

I deleted what I posted because I noticed that I had entered the value with 2 decimal points  6.845.88   as you had stated:

I re-input the value as  6,845.88 and I get the error message that I had set up:  
ErrorMessage="Enter dollars, decimal, cents and commas. (ex: 0.36)."

I used the following code:

<td align="left" width="50%" style="font-family: Arial, Helvetica, sans-serif;
                           font-style: normal; font-weight: bold;color: #00356A; " class="style18"> Dollar Amount:
                           <asp:Label ID="Label4" Text = " " runat ="server" ForeColor="#00356A" Width="2%" />
                           <asp:TextBox ID="txtAmountS" Maxlength="21" runat="server"
                               style="margin-right: 0px" Width="25%" ></asp:TextBox>                  
                           <asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server"
                           ErrorMessage="Enter dollars, decimal, cents and commas. (ex: 0.36)."
                           ControlToValidate="txtAmountS" ForeColor="#FF0066"
                           SetFocusOnError="true"  
                           ValidationExpression="^[0-9]{1,15}(\.[0-9]{1,2})?$">                  
                           </asp:RegularExpressionValidator>

                       &nbsp;<asp:Label ID="lblHowMany" runat="server" Text="How Many" Visible="False"
                               Width="10%"></asp:Label>
&nbsp;
                           <asp:TextBox ID="txtHowManyS" runat="server" Height="25px" Visible="False"
                               Width="12%"></asp:TextBox>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;                  
                           
                       </td>
^\d{0,15}(?:\.\d{0,2})?$
Avatar of zimmer9

ASKER

^\d{0,15}(?:\.\d{0,2})?$

Would this accommodate the thousands separator (commas)?

It appears I get the same error when entering a value with commas.
Here is another approach:
/^(?:0*[1-9]\d*\s*(?:,|$)\s*)+$/gm
ASKER CERTIFIED SOLUTION
Avatar of HainKurt
HainKurt
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial