Alphanumeric Restriction

Published by Matt in

Create a function that returns true if the given string has any of the following:

  • Only letters and no numbers.
  • Only numbers and no letters.

If a string has both numbers and letters, or contains characters which don't fit into any category, return false

Examples

alphanumeric_restriction("Bold") ➞ true

alphanumeric_restriction("123454321") ➞ true

alphanumeric_restriction("H3LL0") ➞ false

alphanumeric_restriction("ed@bit") ➞ false

Notes

Any string that contains spaces or is empty should return false.

Watch a quick demo on how Edabit works.