Regular expression to match 0 or 1

javascript, regex

Solution

Single character, 0 or 1:

/^[01]$/

Multiple 0s or 1s (any order, no other characters):

/^[01]+$/g

Demo (Just add a `+` for the second example. The `gm` at the end in the demo is just for the example because there are multiple lines for test cases)

Problem

I need a regexp to match either 0 or 1 entered into a field and no other characters at all, neither numeric nor alphas. How can I do it?

Original source

Related problems