Precision (p): Total number of digits to the left and right of the decimal
Scale (s): Total number of digits to the right of the decimal
Consider my following regex so far:
^-?[0-9]+(\.[0-9]{1,3})?$
- -? optional negative number
- [0-9] matches numbers 0-9
- "+" any number of digits
- "(\.[0-9]{1,3})?" optional decimal with 1-3 digits
Example:
100.95 has a precision of 5 and a scale of 2 (5,2)
I know how to restrict total numbers to the left, and total numbers to the right, but not sure how to encapsulate the entire value to limit the "p, precision" part, and ignore the period if it exists in that count. The - also needs to be ignored in that total count.
UPDATE:
This seems to be working...
^(?=(\D*\d\D*){0,5}$)-?([0-9]+)?(\.?[0-9]{0,2})?$
blank line matches
0 - match
1 - match
123 - match
123.12 - match
-1 - match
123.122 - no match