紀錄一下覺得寫得很清楚的文章。
http://jim690701.blogspot.tw/2012/12/androidspinner.html
Java Regular Expression的學習筆記 [精華]public static int CheckPassword(String resource) { int length = resource.length(); if (length >= 12 || length < 8) return 0; try { int strong = 0; for (int i = 0; i < length; i++) { if (resource.charAt(i) >= 'a' && resource.charAt(i) <= 'z') { strong++; break; } } for (int i = 0; i < length; i++) { if (resource.charAt(i) >= 'A' && resource.charAt(i) <= 'Z') { strong++; break; } } for (int i = 0; i < length; i++) { if (resource.charAt(i) >= '0' && resource.charAt(i) <= '9') { strong++; break; } } for (int i = 0; i < length; i++) { if (!((resource.charAt(i) >= 'a' && resource.charAt(i) <= 'z') || (resource.charAt(i) >= 'A' && resource.charAt(i) <= 'Z') || (resource.charAt(i) >= '0' && resource.charAt(i) <= '9'))) { strong++; break; } } return strong; } catch (Exception e) { } // 例外 return 0;}
參考了Patterns裡的EMAIL_ADDRESSpublic static boolean isValidPassword(String password){ return Pattern.compile("^(?=.*[a-zA-Z]+)(?=.*\\d+)[a-zA-Z0-9]{8,12}$") .matcher(password).matches();}