Link to home
Start Free TrialLog in
Avatar of VBdotnet2005
VBdotnet2005Flag for United States of America

asked on

Regex - valid $

I need a pattern to valid txtbox like below and blank is not allowed.  I am trying to apply to Regularexpressionvalidator.

0.00
1.00
25.00
100.00
etc


^(?:100,000|(?:(?:(?:\d?\d,)?\d)?\d)?\d)\.\d\d$
Avatar of Terry Woods
Terry Woods
Flag of New Zealand image

That looks good for values up to 100,000.00

Is there anything it's failing to match with where it should match, or vice versa?
Are you saying the above doesn't work, or you'd like to add the $ symbol to the pattern?

The pattern appears to work for me:

User generated image
If you simply want to add the $ symbol, then insert it near the beginning (escaped, of course):

^\$(?:100,000|(?:(?:(?:\d?\d,)?\d)?\d)?\d)\.\d\d$

Open in new window

Avatar of VBdotnet2005

ASKER

If a textbox is blank, it does not catch it.
This will not catch if TextBox1 is blank.

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="RegularExpressionValidator"  ControlToValidate="TextBox1" ValidationExpression="^(?:100,000|(?:(?:(?:\d?\d,)?\d)?\d)?\d)\.\d\d$"></asp:RegularExpressionValidator>
</asp:Content>
I can use Requiredfieldvalidator and RequiredfieldRegularExpression at the same time. It is kind of redundant, but that will work.
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America 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
The thing about using them side by side is the error message displaying.

If textbox1 is empty

textbox1       *required field
 
if textbox1 has an invalid number format

textbox1                                *Invalid format  


Is there a better way?