Solved

Regular expression to validate decimal values in c#

Posted on 2010-08-25
8
2,113 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
8 Comments
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 33524414
Hi kravindra;

This regex pattern should do what you want.

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

Fernando
0
 

Author Comment

by:kravindra
ID: 33524529
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 63

Expert Comment

by:Fernando Soto
ID: 33524689
Please post your code you are working with. I just tested the pattern and all the values you posted work for me.
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

Author Comment

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

here problem  is it's accepting more than 2 character after decimal point.
 could you correct  it please?
0
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 33525029
Try this one

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

Expert Comment

by:Fernando Soto
ID: 33532361
Did that work for you?
0
 

Expert Comment

by:vishal kathar
ID: 41789101
Thank You for Regular expression to valid only decimal should be enter
0
 
LVL 63

Expert Comment

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

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

632 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