1

How can I write a regular expression that would accept only alphanumeric chars and the string's length be 0 or 8? What i managed to do until now is

^[a-zA-Z0-9]{0-8}$

Which verifies that my string contains only alphanumeric chars but still allows any string of length between 0 and 8. Is there any way to separate it in either {0} || {8} (in same regex)

next_user
  • 283
  • 2
  • 11

1 Answers1

2
^(?:[a-zA-Z0-9]{8}|)$

Try this for only 0 or 8.

See demo.

https://regex101.com/r/wU7sQ0/9

vks
  • 63,206
  • 9
  • 78
  • 110