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.
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.
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
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.
ASKER
^\$?[+-]?[\d,]*\.?\d{0,2}$
here problem is it's accepting more than 2 character after decimal point.
could you correct it please?
here problem is it's accepting more than 2 character after decimal point.
could you correct it please?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
This regex pattern should do what you want.
String pattern = @"\d{1,12}\.\d\d";
Fernando