Solved

Regular expression to validate decimal values in c#

Posted on 2010-08-25
8
2,024 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
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 

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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Suggested Solutions

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

751 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