Title |
Test
Find
Pattern Title
|
Expression |
^[1-9]+[0-9]*$ |
Description |
Allows only positive integers that are greater then 0. Easily modified for +/- intergers and allowing zero. |
Matches |
1 | 12 | 124 |
Non-Matches |
-1 | a | 1.0 |
Author |
Rating:
William Powell
|
Source |
Me |
Your Rating |
|
Title: Integers: a few regex
Name: |ON|
Date: 11/19/2014 10:40:11 AM
Comment:
If you only want non-zero positive integers without zero-padding:
without plus-sign: [1-9][0-9]*
with optional plus-sign: \+?[1-9][0-9]*
with mandatory plus-sign: \+[1-9][0-9]*
If you want to allow all positive integers, incl. zero.
without plus-sign: 0|[1-9][0-9]*
without plus-sign before zero: 0|\+?[1-9][0-9]*
with optional plus-sign: \+?(0|[1-9][0-9]*)
with mandatory plus-sign: \+(0|[1-9][0-9]*)
If you want to allow all non-zero integers:
without plus-sign: -?[1-9][0-9]*
with optional plus-sign: [+-]?[1-9][0-9]*
with mandatory sign: [+-][1-9][0-9]*
If you want to allow all integers including zero
(without sign before zero) :
without plus-sign: 0|-?[1-9][0-9]
with optional sign: 0|[+-]?[1-9][0-9]*
with mandatory sign: 0|[+-][1-9][0-9]*
If you want to allow zero-padding, here are some possibilities:
0*[1-9][0-9]*
[+-]?0*[1-9][0-9]*
0+|[+-]?0*[1-9][0-9]*
Title: Pattern Title
Name: Mike
Date: 6/19/2006 5:30:22 PM
Comment:
0 is positive right? ^[0-9]+$ is really what you need
Title: thank you
Name: daniele
Date: 5/18/2004 10:33:39 AM
Comment:
thank you! :-)
Title: Good call...
Name: William Powell
Date: 9/23/2003 8:43:04 PM
Comment:
You were absolutely correct. Changed to be correct.
Title: error
Name: Jason Galvin
Date: 9/23/2003 8:01:43 PM
Comment:
Please correct me if I'm wrong, but according to the description this expression should match "89011", but it doesn't, apparently because this positive integer contains the character zero.