I have the following regular expression which performs very basic validation to allow only integers and should not allow any floating point numbers and negative numbers. I found the below expression as one of the ways to do so:
var reg = new RegExp('^(([0-9]+)|\.[0-9]+)$');
This expression correctly validates the following inputs:
validatePercentage(56.67); --> not an integer
validatePercentage(67); --> integer
validatePercentage(-5667); --> should not be negative
However, I'm unable to understand the usage of '\.' in the expression (that somehow seems to be making a difference to the output). Can somebody please explain how exactly is the regex working to eliminate negative inputs? Thanks in advance.