Reputation: 1
I used decimal regular expression \d{1,5}([.]\d{1,2})?|[.]\d{1,2}
.
It works fine in normal scenario. But when I type value like 55.123
and remove 123
with back space and just leave value as 55.
it shows a validation/error message.
I want to restrict to show message in this case (I mean want to have my validation message not to appear for "55." as this is valid value for me )
Upvotes: 0
Views: 100
Reputation: 31596
Use this pattern
\d+\.?\d*
which says
\d+
that atleast 1 digit preceding is needed but more could follow.\.?
with an optional period. \d*
followed by 0 or more digits.If the pattern needs to not have any possible whitespace, enclose it with the beginning of line/end of line anchors such as
^\d+\.?\d*$
Upvotes: 1