Solved

Regular expression to validate decimal values in c#

Posted on 2010-08-25
8
1,802 Views
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.
0
Comment
Question by:kravindra
  • 5
  • 2
8 Comments
 
LVL 62

Expert Comment

by:Fernando Soto
Comment Utility
Hi kravindra;

This regex pattern should do what you want.

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

Fernando
0
 

Author Comment

by:kravindra
Comment Utility
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
 
LVL 62

Expert Comment

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

Author Comment

by:kravindra
Comment Utility
^\$?[+-]?[\d,]*\.?\d{0,2}$

here problem  is it's accepting more than 2 character after decimal point.
 could you correct  it please?
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
Comment Utility
Try this one

^\$?[+-]?\d{1,12}\.\d{2}$
0
 
LVL 62

Expert Comment

by:Fernando Soto
Comment Utility
Did that work for you?
0
 

Expert Comment

by:vishal kathar
Comment Utility
Thank You for Regular expression to valid only decimal should be enter
0
 
LVL 62

Expert Comment

by:Fernando Soto
Comment Utility
Not a problem Vishal, glad I was able to help.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 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

18 Experts available now in Live!

Get 1:1 Help Now