Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2605
  • Last Modified:

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.
0
kravindra
Asked:
kravindra
  • 5
  • 2
1 Solution
 
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
 
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
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
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:
Try this one

^\$?[+-]?\d{1,12}\.\d{2}$
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now