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*[1-9]+\d*$)|(^[1-9]+\d*\.\d*$)
Description
Accepts only positive decimal values. Zero and negatvie numbers are non-matching. Allows zeros after last non-zero numeric value after decimal place for significant digits.
Matches
0.050 | 5.0000 | 5000
Non-Matches
0 | 0.0 | .0
Author Rating: Not yet rated. Bri Gipson
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: prevent 0 from beging and middle
Name: devaspnet
Date: 4/24/2012 5:54:34 PM
Comment:
i want to match digt (6 lenght) only without begin 0 or 0 between any number example 012345 false 123456 true 100000 true 101000 false 100001 false 110000 true


Title: prevent 0 from beging and middle
Name: devaspnet
Date: 4/24/2012 5:53:34 PM
Comment:
i want to match digt (6 lenght) only without begin 0 or 0 between any number example 012345 false 123456 true 100000 true 101000 false 100001 false 110000 true


Title: Test Find Pattern Title
Name: sai
Date: 9/15/2010 9:24:03 AM
Comment:
I need in same way but I don't want to show any positive numbers. I need is number should be in decimal format and after decimal only two digits should allowed.


Title: Need to Restrict it
Name: Bryan Jackson
Date: 4/20/2005 12:32:45 PM
Comment:
This is perfectexcept I need to restrict it to only allow up to 100. How do I add that? Thanks!!


Title: Thanks for explaining
Name: Julie C
Date: 4/5/2005 11:47:27 PM
Comment:
Hi Bri, Thanks for taking the time to explain the query. I am learning regex by starting with working examples. My goal is to define a regex that allows leading 0s, requires at least one non-0 digit and is up to 6 positions (no decimals). I morphed your regex into ^(?=.*[1-9].*$)\d{0,6}?$ and it seems to do the trick. Will you validate that my interpretation of this regex is correct? (?=.*[1-9].*$) --> look ahead for any character, 0 or more times (is this to let the 0s match?), 1-9,any character 0 or more times (is this to let the 0s match?) \d{0,6}? --> a digit, 0 to 6 times,once or not at all Thx, JC


Title: Positive {16,7} SQL Decimal, allowing lead zeros
Name: Bri Gipson
Date: 4/5/2005 8:22:17 PM
Comment:
Julie C, Please try the expression at http://www.regexlib.com/REDetails.aspx?regexp_id=1049 to see if it fulfills your requirement.


Title: Positive {16,7} SQL Decimal, allowing lead zeros (cont)
Name: Bri Gipson
Date: 4/5/2005 8:12:53 PM
Comment:
To cap the query so that the entire string must comply to the expression and to make the decimal optional we get: ^(?=.*[1-9].*$)\d{0,7}(?:\.\d{0,9})?$ Sometimes I make things harder than they have to be, but to enforce the no-leading-zero-unless-necessary rule that I assumed would be needed, the longer query that you are trying to change was produced.


Title: Positive {16,7} SQL Decimal, allowing lead zeros
Name: Bri Gipson
Date: 4/5/2005 8:12:19 PM
Comment:
Julie C, Allowing lead zeros is simpler than forcing the first significant digit. ^\d{0,6}$ for example would allow a string of numeric characters from a length of 0 to 6 characters. To force a positive value (non-zero value) you have to have at least one character from 1-9. \d*[1-9]\d* does the trick and allows leading zeros, but now we don't have anything to specify this as being a string from 0 to 6 characters in length. That's what the look-ahead is for. It looks first to make sure we are within our bounds of a 0 to 6 character long numeric string. The expression you are wanting to modify already allows a leading zero so I'm guessing you want the user to be able to enter in 002.2351 as a valid string. By changing the character requirements to force our {16,9} (SQL style) number we would have the following expression: \d{0,7}\.\d{0,9} To force this value to have at least one non-zero digit we could simple look ahead: (?=.*[1-9].*)\d{0,7}\.\d{0,9} To cap the quer


Title: look ahead
Name: Julie C
Date: 4/5/2005 4:47:02 PM
Comment:
Bri, Can you explain what the look ahead ?=\d{1,9}$ is doing in the 16, 9 example? I am trying to morph this into a "allow leading 0 up to 6 position positive" regex. From your example: (^([1-9]\d{0,6}|0)\.(?=\d{1,9}$)\d*[1-9]\d*$)|(^[1-9]\d{0,6}(\.\d{0,9})?$) Thanks!


Title: allow leading 0s
Name: Julie C
Date: 4/5/2005 11:44:37 AM
Comment:
Thanks. ^[1-9]\d{0,5}$ works great! What about allowing leading 0s?


Title: one to six digit positive integer
Name: Bri Gipson
Date: 4/5/2005 10:42:39 AM
Comment:
^[1-9]\d{0,5}$ Accepts: 1 123456 Doesn't Accept: 01 0 1234567


Title: great validator
Name: Julie C
Date: 4/5/2005 9:27:55 AM
Comment:
How do I convert this to allow positive integers up to 6 digits?


Title: Ammending to accept 0.00 specifically
Name: Bri Gipson
Date: 3/28/2005 12:44:43 PM
Comment:
(^\d*\.?\d*[1-9]+\d*$)|(^[1-9]+\d*\.\d*$)|(^0\.00$) will allow 0.00 to also be accepted. Note this is literal and will be captured in the third group. If you want more flexability then you are asking for non-negative values which is simply ^\d*\.?\d*$ Cheers, -Bri


Title: restriction sample
Name: Bri Gipson
Date: 3/28/2005 12:41:33 PM
Comment:
(^([1-9]\d{0,6}|0)\.(?=\d{1,9}$)\d*[1-9]\d*$)|(^[1-9]\d{0,6}(\.\d{0,9})?$) This will accept 0.12 but not 00.12. It also will accept 1234567.123456789 but not 12345678.123456789. {16,9} is interpreted as MS Sql would, meaning 16 full (available) digits from which 9 are to the right of the decimal. This has not been fully tested, but in brief tests appears to produce what you want.


Title: not quite what i'm after
Name: laura herald
Date: 3/26/2005 6:23:16 PM
Comment:
its the closest ive found here mind you i would like it to also match 0.00 if possible how should i amend it for this?


Title: restriction
Name: gel
Date: 3/24/2005 1:21:05 AM
Comment:
do you know how to restrict this validator to decimals of 16,9?


Title: Nice... thanks
Name: José Terranova
Date: 3/19/2005 11:15:23 PM
Comment:
Thanks...this solve many problems.


Title: very good
Name: penny
Date: 3/17/2005 8:44:40 AM
Comment:
??????,??


Title: Perfect
Name: Rich B
Date: 4/22/2004 10:16:06 PM
Comment:
This is just what I was looking for. Thanks for posting it.


Title: Nice and Simple -KISS FACTOR
Name: kristie Mansfield
Date: 11/7/2003 12:08:03 PM
Comment:
good - thanks for posting this..


Title: Exactly what I was looking for
Name: Joe Herr
Date: 6/4/2003 2:51:29 AM
Comment:
Thanks. This is exactly what I needed for a one of my validation controls.


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