Link to home
Start Free TrialLog in
Avatar of kravindra
kravindra

asked on

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.
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Hi kravindra;

This regex pattern should do what you want.

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

Fernando
Avatar of kravindra
kravindra

ASKER

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
Please post your code you are working with. I just tested the pattern and all the values you posted work for me.
^\$?[+-]?[\d,]*\.?\d{0,2}$

here problem  is it's accepting more than 2 character after decimal point.
 could you correct  it please?
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
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
Did that work for you?
Thank You for Regular expression to valid only decimal should be enter
Not a problem Vishal, glad I was able to help.