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

前端 未结 7 1553
孤城傲影
孤城傲影 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 13:06

    If you are looking to check whether your string contains uppercase letter or not, you can use below pattern:

    String s="abcDe_shdgwU";    //you can have any String here
    
    if(s.matches(".*[A-Z].*"))
       System.out.println("The String contains Uppercase letter(s)");
    else
      System.out.println("does not contain Uppercase letter(s)");
    

    Hope that helps. Thank you. Regards, Tanumay Saha

    0 讨论(0)
提交回复
热议问题