Max value being
Other valid values:
I've searched all over with no joy.
Tezra's formula fails for '1.' or '1.0'. For my purposes, I allow leading and trailing zeros, as well as a leading + or - sign, like so:
In a recent project we needed to alter this version in order to meet international requirements.
This is what we used:
Creating a named group
(?<tt>\.|\,| ) allowed us to use the negative look ahead
(?!\k<tt>)[\.|\,]) later to ensure the thousands separator and the decimal point are in fact different.
First, I want to point out that if you own the form the data is coming from, the best way to restrict the input is to use the proper form elements (aka, number field)
<input type="number" name="size" min="0.01" max="9,999,999.99" step="0.01">
Whether "," can be entered will be based on the browser, but the browser will always give you the value as an actual number. (Remember that all form data must be validated/sanitized server side as well. Never trust the client)
Second, I'd like to expand on the other answers to a more robust (platform independent)/modifiable regex.
[1-9]for "a non-zero number" so
Putting it all together
About the minimum and maximum values... Well, I wouldn't do it with a regex, but you can add lookaheads at the beginning:
Note: this allows
0,999.00, so you may want to change it to:
which would not allow a leading 0.
It worked on a few, but I'm still learning regex as well.
The logic should be 1-3 digits 0-1 times, 1 comma followed by 3 digits any number of times, and a single . followed by any number of digits 0-1 times
I have used below regrex for following retrictions -
©2020 All rights reserved.