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

后端 未结 4 834
孤城傲影
孤城傲影 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条回答
  •  -上瘾入骨i
    2020-12-09 05:58

    It can be done quickly by 3 regular expression.

    function check($string){
       return    preg_match("/[`!%$&^*()]+/", $string) 
              && preg_match("/[a-z]+/", $string) 
              && preg_match("/[A-Z]+/", $string) ;
    }
    

    Dont forget to tweak the list of special characters. Because I dont know what characters you think are special.

    I believe wasting a lot of time on a single line regex while you are not expert will not increase your productivity. This 3 regex solution will do just fine. It saves time.

提交回复
热议问题