Regular expression to validate decimal values in c#

Posted on 2010-08-25
Last Modified: 2016-09-08
I want a regular expression to validate decimal values.

it should allows 12 numerics values and 2 decimal values only.

it should not allow more than 12 decimal values and more than 2 decimal values.
Question by:kravindra
  • 5
  • 2
LVL 62

Expert Comment

by:Fernando Soto
ID: 33524414
Hi kravindra;

This regex pattern should do what you want.

String pattern = @"\d{1,12}\.\d\d";


Author Comment

ID: 33524529
String pattern = @"\d{1,12}\.\d\d";

this expression is not accepting numbers.

I want a regular expression that should accept 12 numeric number and decimal point .
after decimal point it should accept 2 decimal only.

LVL 62

Expert Comment

by:Fernando Soto
ID: 33524689
Please post your code you are working with. I just tested the pattern and all the values you posted work for me.

Author Comment

ID: 33524839

here problem  is it's accepting more than 2 character after decimal point.
 could you correct  it please?
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

LVL 62

Accepted Solution

Fernando Soto earned 500 total points
ID: 33525029
Try this one

LVL 62

Expert Comment

by:Fernando Soto
ID: 33532361
Did that work for you?

Expert Comment

by:vishal kathar
ID: 41789101
Thank You for Regular expression to valid only decimal should be enter
LVL 62

Expert Comment

by:Fernando Soto
ID: 41789285
Not a problem Vishal, glad I was able to help.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Achieve json result 2 66
Need to pass a connection through class/Method 1 40
C# application error "Parameter Is Not Valid". 3 80
Export import database 4 45
Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

863 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

19 Experts available now in Live!

Get 1:1 Help Now