0

I'm trying to develop a regex for password validation that requires the following criteria,

  • 1 Uppercase
  • 1 Numeric
  • 8-45 length
  • Ascii only as specified in OWASP list

I came up with this lookahead regex but unfortunately it doesn't seem to work with non-ascii characters.

^(?=.*[A-Z])(?=.*\d)(?=[\x20-\x7E]).{8,45}$

Tested on,

ABCD1234abcd!" #$%&'()*+,-./:;<=>?@[\]^_`{|}~ 

However, doesn't seem to work with non-ascii characters i.e. it still matches the non-ascii characters despite of \x20-\x7E,

ABCD1234abcd!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~£

Notice that I do want to include the whitespace as well.

Anything obvious that I'm doing wrong here ?

nixgadget
  • 6,983
  • 16
  • 70
  • 103

1 Answers1

3

Your regex allows any character via the dot .. Your look ahead only required the first character to be ascii.

Change the dot to your ascii range:

^(?=.*[A-Z])(?=.*\d)[\x20-\x7E]{8,45}$
revo
  • 47,783
  • 14
  • 74
  • 117
Bohemian
  • 412,405
  • 93
  • 575
  • 722