I want a regular expression for the following values:
1) .1 = False.
2) 0.1 = True.
3) 1.1245 = True.
4) 1.2. = False.
5) 1.24.35 = False.
6) 21.152 = true.
This regex should check that the string represents an integer or is composed of only numbers and a single . representing a decimal point.
I am using: /^[\+\-]?\d*\.?\d+(?:[Ee][\+\-]?\d+)?$/ but it takes "1.2." as true.
/^[\+\-]?\d*\.?\d+(?:[Ee][\+\-]?\d+)?$/.test('1.2.')returnsfalse, nottrue. Cannot reproduce what you are saying.Number(x) === Number(x); when NaN, it will return false becauseNaN === NaNalways returns false.