regex:numbers
This is an old revision of the document!
Regex - Numbers
Specific number of digits only
0 and numbers not begin with 0
^(0|[1-9][0-9]*)$
Numbers not begin with 0 and maximum 2 decimals
^([1-9][0-9]*)+(.[0-9]{1,2})?$
Positive or Negative numbers with maximum 2 decimals
^(\-)?\d+(\.\d{1,2})?$
Positive, Negative numbers and any decimal length
^(\-|\+)?\d+(\.\d+)?$
Numbers with maximum 2 decimals
^[0-9]+(.[0-9]{2})?$
Numbers with 1-5 decimals
^[0-9]+(.[0-9]{1,5})?$
Positive Integer, excluding 0
^[1-9]\d*$
or
^([1-9][0-9]*){1,3}$
or
^\+?[1-9][0-9]*$
Negative Integer, excluding 0
^-[1-9]\d*$
or
^\-[1-9][0-9]*$
Positive Integer
^\d+$
or
^[1-9]\d*|0$
Negative Integer
^-[1-9]\d*|0$
or
^((-\d+)|(0+))$
regex/numbers.1663715193.txt.gz · Last modified: 2022/09/20 23:06 by peter