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
it?
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!

/*
PLUG: http://plug.org, #utah on irc.freenode.net
Unsubscribe: http://plug.org/mailman/options/plug
Don't fear the penguin.
*/

Reply via email to