Validate Pin

Published by Werdna in

Create a function to test if a string is a valid pin or not.

A valid pin has:

  • Exactly 4 or 6 characters.
  • Only numerical characters (0-9).
  • No whitespace.

Examples

valid("1234") ➞ true

valid("45135") ➞ false

valid("89abc1") ➞ false

valid("900876") ➞ true

valid(" 4983") ➞ false

Notes

Empty strings should return false when tested.

Watch a quick demo on how Edabit works.