Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript RegExp passwd validation

I have password constraints that i would like to validate:

  • minimum length = 6
  • upper case and lower case characters allowed
  • at least 1 character (upper- or lowercase)
  • at least 1 digit
  • allowed special characters: _$#%&!?-.

Currently my regex looks like this:

/^(?=.*\d+)(?=.*[a-zA-Z])[0-9a-zA-Z\_\$\#\%\&!\?\-\.]{6,}$/

Except for the special characters, all requirements are met. Can anybody explain to me what i am doing wrong with the special characters? As you can see, every character is escaped and grouped into a "allowed" character class. However, the test still fails.

thank you

like image 451
DucatiNerd Avatar asked Apr 18 '26 18:04

DucatiNerd


1 Answers

/^(?=.{6})(?=.*[a-zA-Z])(?=.*\d)[\w$#%&!?.-]+$/

or

/^(?=.{6})(?=.*[a-z])(?=.*\d)[\w$#%&!?.-]+$/i
like image 190
Ωmega Avatar answered Apr 21 '26 08:04

Ωmega