Regular expression to validate decimal values in c#

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.
kravindraAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Fernando SotoConnect With a Mentor RetiredCommented:
Try this one

^\$?[+-]?\d{1,12}\.\d{2}$
0
 
Fernando SotoRetiredCommented:
Hi kravindra;

This regex pattern should do what you want.

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

Fernando
0
 
kravindraAuthor Commented:
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.

eg:123456789012.22
12.22
33.88
55555.88
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
Fernando SotoRetiredCommented:
Please post your code you are working with. I just tested the pattern and all the values you posted work for me.
0
 
kravindraAuthor Commented:
^\$?[+-]?[\d,]*\.?\d{0,2}$

here problem  is it's accepting more than 2 character after decimal point.
 could you correct  it please?
0
 
Fernando SotoRetiredCommented:
Did that work for you?
0
 
vishal katharCommented:
Thank You for Regular expression to valid only decimal should be enter
0
 
Fernando SotoRetiredCommented:
Not a problem Vishal, glad I was able to help.
0
All Courses

From novice to tech pro — start learning today.