Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Regular expression to validate decimal values in c#

Posted on 2010-08-25
8
Medium Priority
?
2,307 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 64

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 64

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
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 

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 64

Accepted Solution

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

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

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 64

Expert Comment

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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Question has a verified solution.

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

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…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

926 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