-1

I am new to regExp and need to check a password field that accepts 8 to 20 letters.

I have tried str.test or str.match but they return true even when letters can exceed 20.

Is there a native method that can return true/false based on exact match.

RegExp

/.{8,20}/
Jim_Mcdonalds
  • 426
  • 5
  • 15

1 Answers1

-1

Yes, you can use the following:

/^.{8,20}$/.test(yourString)

or

yourString.length >= 8 && yourString.length <= 20
Alex
  • 1,457
  • 1
  • 13
  • 26