My current challenge involves error handling for 2 input values, where I am using regex to ensure that the input is always a number. The issue arises when I want to avoid triggering error handling if the user enters '0'. Currently, I am using the following code snippet:
number = parseInt(incomingValue) || ""
to assign a value to my variable. The problem is that this code turns '0'
into ""
While it is acceptable for an empty value to be assigned an empty string, as I disable my error checking when the lengths are equal to 0
, I do need to correctly convert '0'
into the number 0
. Any suggestions on how to achieve this?
Furthermore, I am looking for a solution to convert '000'
(and similar inputs) into the number 0