I'm going to give an example with react usage. It uses state which store the value of the field. But, I think u can replace it with whatever variable you like.
In my case, myNumber stores a year number. This way, the year 2018 (for example) won't be displayed mistakenly as 02018.