Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- String password = "olav2009";
- // Contains at least one letter between a-z and one letter between 0-9
- System.out.println("Regex way: " + password.matches("[a-z]*{1}[0-9]*{1}"));
- char[] charArray = password.toCharArray();
- boolean isValid = false;
- for(int i = 0; i< charArray.length; i++){
- if(Character.isLetterOrDigit(charArray[i])){
- isValid = true;
- break;
- }
- }
- System.out.println("Complicated way: "+isValid);
- }
- }
Add Comment
Please, Sign In to add comment