regex:numbers
This is an old revision of the document!
Regex - Numbers
Specific number of digits only
2-5 digits
^\d{2,5}$
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+))$
Positive floating-point
^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$
or
^[1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0$
Negative floating-point
^((-\d+(\.\d+)?)|(0+(\.0+)?))$
or
^-([1-9]\d*\.\d*|0\.\d*[1-9]\d*)$
or
^(-([1-9]\d*\.\d*|0\.\d*[1-9]\d*))|0?\.0+|0$
or
^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$
Floating-point
^-?([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$
regex/numbers.1663714882.txt.gz · Last modified: 2022/09/20 23:01 by peter