Guest User

Untitled

a guest
Jul 16th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. public class Main {
  2.  
  3. /**
  4. * @param args the command line arguments
  5. */
  6. public static void main(String[] args) {
  7. String password = "olav2009";
  8. // Contains at least one letter between a-z and one letter between 0-9
  9. System.out.println("Regex way: " + password.matches("[a-z]*{1}[0-9]*{1}"));
  10.  
  11. char[] charArray = password.toCharArray();
  12.  
  13. boolean isValid = false;
  14. for(int i = 0; i< charArray.length; i++){
  15. if(Character.isLetterOrDigit(charArray[i])){
  16. isValid = true;
  17. break;
  18. }
  19. }
  20. System.out.println("Complicated way: "+isValid);
  21. }
  22.  
  23. }
Add Comment
Please, Sign In to add comment