- The first Regular Expression Library on the Web!

Please support RegExLib Sponsors


Regular Expression Details

Title Test Find Pattern Title
^\d{0,2}(\.\d{1,4})? *%?$
An expression for .NET regular expression validation controls intended to faciliate the entry of percentage values both a whole numbers or as their decimal representations. Also compatible with the default US format for string formatting for percentages. Recommend that if you intended accept a value passing this express that you strip the percentage signs and take measures to ensure that any whole values are converted to percentages.
4.0% | 0.45 | .0345
123 | %12
Author Rating: Not yet rated. brent stineman
Your Rating
Bad Good

Enter New Comment

Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Title: Works for me!
Name: Jay
Date: 1/25/2011 11:47:59 AM

Title: 100% still an issue
Name: jimmy
Date: 5/29/2009 9:53:45 AM
It still allows for 100.1 to be entered.

Title: again me
Name: Michel Albert
Date: 4/21/2004 3:04:08 PM
Ok... I think I have it now: ^(100|\d{0,2})(\.\d{1,4})? *%?$ so it may start with either "100" or a 2 digit number. that should do the trick

Title: 100% problem solved
Name: Michel Albert
Date: 4/21/2004 3:00:35 PM
Oops... sorry for the quick question as I have figured this out only fractions of a second later.... this will do: ^1?\d{0,2}(\.\d{1,4})? *%?$ so by simply adding the "1?" in the beginning it allows a 1 in front of the expression. hmmm... but thinking about this, it now also allows values up to 199.9999 which is not really desirable... :(

Title: 100% problem
Name: Michel Albert
Date: 4/21/2004 2:56:31 PM
This seems to be the only regexp which is working for me as it seems, and I would need one which allows 100%

Title: author response
Name: Brent
Date: 2/17/2004 1:55:59 PM
That's because the expression only allows for a value of 2 digits before the decimal. It can be easily expanded to allow any percentage above 99.999. But that raises the question of *if* if needs to allow for percentages over 100% or not. Let me know what you all think and I'll make the changes.

Title: Does Not Match Value "100%"
Name: jbfraley
Date: 2/16/2004 2:36:14 PM
When tested in an ASP.NET regular expression validator control, it does not match the value "100%"

Title: Doesn't allow 100%
Name: Paul
Date: 2/1/2004 10:21:54 PM
This regular expression doesn't allow percentages of 100

Copyright © 2001-2018, | ASP.NET Tutorials