Regex golf, is this a valid PIN?

S. Dale Morrey sdalemorrey at
Mon Feb 24 03:25:59 MST 2014

I have a site where the user needs to enter a PIN into a field.
The defining characteristics of a PIN are that it is numeric, but it
doesn't necessarily have to be a number, just a string of digits.

I found this on a google search, it is adapted from a piece of code that
looks for normal integers.

function isPIN(str) {
        return /^\+?(0|[0-9]\d*)$/.test(str);

But I don't think it would work in a case where a pin starts with 0 would
For instance would 0123456789 return true or false with this?
Is there a better regex than this that could also do the trick?
Is there extra cruft that could or ought to be eliminated? (my regex fu
sucks bad)

Thanks in advance!

More information about the PLUG mailing list