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*$
Description
Matches any floating point numer/numeric string, including optional sign character (+ or -). Also matches empty strings.
Matches
123 | +3.14159 | -3.14159
Non-Matches
abc | 3.4.5 | $99.95
Author Rating: Not yet rated. Steven Smith
Source
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: Problematic Matches: Matches Decimal Point/Sign
Name: Theriault
Date: 4/27/2009 10:06:50 PM
Comment:
This regular expression can match a decimal point alone, a negative sign alone, and a positive sign alone. This will obviously result in an error in many languages during conversion. Please use the regular expression provided by Darren Neimke below.


Title: how to write Regular Expression for empty strings and only -ve decimal
Name: how to write Regular Expression for empty strings and only -ve decimal
Date: 3/20/2009 1:29:13 PM
Comment:
how to write parter for empty strings and only -ve decimal if i remove + then also it verify +ve values. ^[-]?\d*\.?\d*$


Title: Empty Strings
Name: Darren Neimke
Date: 8/12/2003 4:17:08 PM
Comment:
As mentioned, this pattern also matches empty strings. To ensure that a number is present use alternation like so: ^[-+]?(\d+(?:\.?\d*)|\d*\.\d+)$ This is basically saying: - Match from the beginning of the input - Match an OPTIONAL +/- sign - Match either any amount of numbers followed by OPTIONAL trailing decimal point and numbers OR OPTIONAL numbers followed by COMPULSORY decimal point and numbers.


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