Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular expressions for password validation

Tags:

regex

I need to validate a password that matches the following criteria:

  • minimum 8 characters
  • contain a combination of numbers and letters
  • must not enforce special characters

The follow regular expression is what I came up with:

^{8,}.(?=*\d)(?=.*[a-zA-Z])&

but this is failing on:

  • !password1
  • password1
  • Password1

From what I can gather, trying to investigate RegEx, {8,} means minimum of 8 and don't care about the maximum, \d specifies digits, whitespaces and special characters. The a-z makes sense.

like image 213
JadedEric Avatar asked Jun 05 '26 05:06

JadedEric


1 Answers

Try:

^(?=.*\d)(?=.*[a-zA-Z]).{8,}$

See it @work

like image 121
codaddict Avatar answered Jun 06 '26 18:06

codaddict



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!