I want to write a regex that allows an integer number, or a decimal number with 0 - 2 decimal digits.
Valid Input
1
1.
1.1
1.11
111111111
111111111.
111111111.1
111111111.11
Invalid Input
a
a.
1.a
1.111
1.1111
- string allows any number of digit characters, but only allows 1 decimal/period
- if a period/decimal exists: only allow 2 digit characters after the decimal
Here is the regex I came up with
\d*\.?([\d]){0,2}
I am having trouble testing it to ensure it works. I found a couple ways of testing it. Using the test method which I just used w3schools setup here. The other way was with some javascript regular expression tester like regexr and regex101. For all of these: it appears that either my regular expression is returning false positives, or my regular expression does not work as intended.
Question: What regex would do what I want it to do?
^\d*\.?([\d]){0,2}$