regex to allow atleast one special character, one uppercase, one lowercase(in any order)

后端 未结 4 836
孤城傲影
孤城傲影 2020-12-09 05:51

Can anyone help me with a regex to allow atleast one special character, one uppercase, one lowercase.

This is what I have so far:



        
4条回答
  •  死守一世寂寞
    2020-12-09 06:05

    Your regex

    ^.*(?=.{8,})(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=]).*$
    

    should actually work just fine, but you can make it a lot better by removing the first .*:

    ^(?=.{8,})(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=]).*$
    

    will match any string of at least 8 characters that contains at least one lowercase and one uppercase ASCII character and also at least one character from the set @#$%^&+= (in any order).

提交回复
热议问题