Correct regex for a password-type field -


working on password-field.

the regex expression field container letters (lowercase, uppercase), digits , special characters this:

^([a-z,a-z,0-9,#,$,%,&,_,]{8,20})*$ 

tell me please, how should modified if want every pass phrase have @ least 1 lowercase, 1 uppercase , 1 digit?

for example, 3-characters long pass is:

  • 'ab3' - pass
  • 'ab3' - fail

you need use lookaheads , need remove commas present inside character class.

^(?=.*?[a-z])(?=.*?[a-z])(?=.*?\d)[a-za-z0-9#$%&_]{8,20}$ 

note password must atleast 8 , atmost 20 chars long.

demo


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -