I need a regex in which decimal is optional. If decimal is there then there can be max 6 digits before and max 2 digits after decimal. If decimal is not there then max of 6
^\d{0,6}(\.\d{1,2})?$
Try this.See demo.
https://regex101.com/r/oL9kE8/4
Just make the (\.\d{1,2}) decimal part optional.?
(\.\d{1,2})
?