Solved

RegEx in C# to accept decimal

Posted on 2009-07-12
6
686 Views
Last Modified: 2013-12-17
Hi

I need a Regular Expression that accept decimal as:

1 - At maximum 6 digits.
2.- A dot if there is a fraction.
2 - At maximum 2 digit for fraction.

The number must be equal 0.01 or over.


0
Comment
Question by:Almatrodi
  • 3
  • 2
6 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 500 total points
Comment Utility
I would use the following:

^\d{0,6}(\.\d{1,2})?$
0
 
LVL 55

Assisted Solution

by:Jaime Olivares
Jaime Olivares earned 500 total points
Comment Utility
this one will avoid a value of zero:
(?!^0*$)(?!^0*\.0*$)^\d{1,6}(\.\d{1,2})?$
0
 
LVL 1

Author Comment

by:Almatrodi
Comment Utility

Dear Jaime

It is ok for me. But it accepts 0.00
The number must be over 0.01

Waiting

Thanks

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 27

Expert Comment

by:ddrudik
Comment Utility
Consider:
^(?!0+(?:\.00?)?$)\d{0,6}(?:\.\d\d?)?$

Open in new window

0
 
LVL 1

Author Comment

by:Almatrodi
Comment Utility
It seems that there is no more answer :(

0
 
LVL 1

Author Closing Comment

by:Almatrodi
Comment Utility
I still did not get the complete answer
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now