RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Pattern Title
Expression
^\d+(?:\.\d{0,2})?$
Description
Matches positive whole numbers with exactly zero or two decimal points if a . is present. Useful for checking currency amounts, such 5 or 5.00 or 5.25.
Matches
1 | 1.23 | 1234.45
Non-Matches
a1.34 | 1.23a | a
Author Rating: The rating for this expression. Andrew van der Stock
Source From Vidottom's comments
Your Rating
Bad Good

Enter New Comment

Title

Name

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: Error
Name: Joey
Date: 3/11/2009 3:27:03 PM
Comment:
it matches 1. ^\d+(?:\.\d{2,2})?$ would be better


Title: Try It (Correct)
Name: Vidottom
Date: 2/3/2004 7:28:07 AM
Comment:
You can try this expression ^\d+(?:\.\d{0,2})?$


Title: Try It
Name: Vidottom
Date: 2/3/2004 7:24:56 AM
Comment:
You can try this expression /^\d+(?:\.\d{0,2})?$/


Title: I rated this a "2"
Name: Darren Neimke
Date: 1/22/2004 4:40:27 AM
Comment:
... I'm sorry, but, unfortunately this pattern needs quite a bit of work - in my opinion :-) Sure, it *will* match stuff like: 1 and 1.23 and even, 9999999999999999999999999999999 Unfortunately it also matches a couple of undesirables. Firstly, it will match 'Nothing'. Because \d* means that you can have zero or more digits and (|d{2}) means nothing or 2 digits so, you can have Nothing and Nothing. Secondly, because you haven't "escaped" the dot "." in the parenthesis, it means "Match any character". This means that your pattern would also match: "5z89".


Copyright © 2001-2024, RegexAdvice.com | ASP.NET Tutorials