A ZIP code is not a number. 01001
and 00501
are valid ZIP codes. 1001
and 501
are not valid ZIP codes. A three- or four-digit number is never a valid ZIP code.
It seems like you're trying to solve the problem of validating a ZIP code after its leading zeroes have been dropped because it was converted to a number, when the problem you should be solving is preventing the ZIP code from being converted to a number in the first place. Leading zeroes in a ZIP code are significant, and if some part of your app strips them, that's the part you need to fix. A ZIP code is not a number.
As @Ultimater wrote above, if the user enters fewer than five digits, it should be rejected, with a gentle reminder that they need to enter either five or nine digits. If for some reason part of your app is converting ZIP codes to numbers and you can't fix that part, then when you do validation you should first convert the number to a string and pad it with zeroes until you have five digits. Don't try to make your validation work with three- and four- digit numbers, because those are never valid ZIP codes.