I have a problem and it is that I am trying to limit a numeric field with a regular expression. So that you can only enter a maximum of 6 natural numbers and 3 decimals. Namely
- 123456 = OK
1234567 = Wrong
123456,123 = Success
However, I can't get to that limitation. The most I've gotten on my own is this:
^(([0-9]{0,5})?(.[0-9]{0,2}))?$
You don't need to use the numeric containers, you can use this:
\d
allows you to capture digits (which is the same as express[0-9]
) at least 1 to 6 times ({1,6}
) from the start of the line (^
). The character?
allows you to capture between 0 and 1 times the expression that is inside the container that it follows ((\.\d{1,3})
).Finally with
\.
captures the literal point followed by at least 1 to 3 digits (\d{1,3}
), all this until the end of the line ($
).