0

I need to program my code to only let users input 3 asterisk or 3 alphabets. The 2 different characters can't be used together. How can I do that?

For instance, user can input *** or AAA

I looked up some stuff on here and all I got was regEx = \d{3}[a-zA-Z]{3}$/;

This did not work for me.

AnsonH
  • 1,525
  • 2
  • 12
  • 25
Tink89
  • 3
  • 1

1 Answers1

2

You can use this regex:

^(?:\*{3}|[A-Za-z]{3})$

Between the beginning of the string ^ and the end of the string$, you can specify 3 times an * \*{3} or | 3 times [A-Za-z]{3}.

(?: is a non capturing group.

The fourth bird
  • 127,136
  • 16
  • 45
  • 63