^[0-9]+(\.([0-9]{1,2})?)?$
Will make things like 12.
accepted. This is not what is commonly accepted but if in case you need to be “flexible”, that is one way to go. And of course [0-9]
can be replaced with \d
, but I guess it’s more readable this way.