How do I check if a Java String contains at least one capital letter, lowercase letter, and number?

前端 未结 7 1634
孤城傲影
孤城傲影 2020-12-16 12:38

I know that I could do this with a series of for loops that iterate through the string but that would be terrible programming. Well, my professor prefers I don\'t do it this

7条回答
  •  粉色の甜心
    2020-12-16 12:55

    Try regular expression

    ^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).+$
    
    descriptions are as follow
    (?=.*[a-z])  -- check lower case letter
    (?=.*[A-Z]) -- check upper case letter
    (?=.*\d) -- check one digit exists
    

提交回复
热议问题