• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 625
  • Last Modified:

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$
0
VBdotnet2005
Asked:
VBdotnet2005
  • 4
  • 2
1 Solution
 
Terry WoodsIT GuruCommented:
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?
0
 
käµfm³d 👽Commented:
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:

Screenshot
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

0
 
VBdotnet2005Author Commented:
If a textbox is blank, it does not catch it.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
VBdotnet2005Author Commented:
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>
0
 
VBdotnet2005Author Commented:
I can use Requiredfieldvalidator and RequiredfieldRegularExpression at the same time. It is kind of redundant, but that will work.
0
 
käµfm³d 👽Commented:
Yes, the RegularExpressionValidator does not (by design) validate empty strings. You will have to also use a RequiredFieldValidator.
0
 
VBdotnet2005Author Commented:
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?
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now