/**//* * Validate password follow setups: * 1. if parameter is null return false; * 2. if parameter's length is not from 8 to 15 return false; * 3. if parameter include other character return false; * 4. if parameter has group of CapitalCharacter or Lowercase or Number or SpecialCharacter * and more then three groups then return true whereas return false; * */ publicstaticboolean validatePassword(String str){ boolean isValidated =false; if(str==null){return isValidated;}//setup 1 if(str.length()<8|| str.length()>15){return isValidated;}//setup 2 String includeOthers="[a-z|A-Z|0-9|@#$%]+"; //setup 3 Pattern p = Pattern.compile(includeOthers); Matcher m = p.matcher(str); if(!m.matches()){ return isValidated; // include other invalid character, return false; } String validate="([0-9]+)|([a-z]+)|([A-Z]+)|([@#$%]+)"; //setup 4 p = Pattern.compile(validate); m = p.matcher(str); boolean hasCapitalCharacter =false; boolean hasLowercase =false; boolean hasNumber =false; boolean hasSpecialCharacter =false; while (m.find()) { if(m.group(1)!=null&&!"".equals(m.group(1))) hasNumber =true; if(m.group(2)!=null&&!"".equals(m.group(2))) hasLowercase =true; if(m.group(3)!=null&&!"".equals(m.group(3))) hasCapitalCharacter =true; if(m.group(4)!=null&&!"".equals(m.group(4))) hasSpecialCharacter =true; } int count =0; if(hasCapitalCharacter)count++; if(hasLowercase)count++; if(hasNumber)count++; if(hasSpecialCharacter)count++; if(count>=3)isValidated =true; return isValidated; }