Advertisement
Guest User

Untitled

a guest
Aug 27th, 2014
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. boolean checkPassword(String pw){
  2.     int len = pw.length();
  3.     String ePattern = "[\\p{ASCII}áéíóöőúüű]{" + len + "}";
  4.         Pattern p = java.util.regex.Pattern.compile(ePattern);
  5.         Matcher m = p.matcher(first);
  6.    
  7.         if(!m.matches()){
  8.             ReccosB.showError("A Jelszó nem tartalmazhatja a következő karaktereket: " + findIllegalChars(pw));
  9.             return false;
  10.      }
  11.     return true;
  12. }
  13.    
  14. /**
  15.  * Returns the characters that doesn't match the regular expression: [\\p{ASCII}áéíóöőúüű] separated with spaces.
  16.  * Repeating characters will appear only once in the return value.
  17.  *
  18.  * Example: findIllegalChars("{ß@}{×}$ßv`°") will return "ß × °"
  19.  */
  20.    
  21. private String findIllegalChars(String input){
  22.    
  23.     String pattern = "[\\p{ASCII}áéíóöőúüű]";
  24.     Pattern p = java.util.regex.Pattern.compile(pattern);
  25.  
  26.     String ret = "";
  27.     for(int i=0; i<input.length(); i++){
  28.         char[] c = new char[1];
  29.         c[0] = input.charAt(i);
  30.         String s = new String(c);
  31.         System.out.println("checkking " + s);
  32.        
  33.         Matcher m = p.matcher(s);
  34.         if(!m.matches()){
  35.             if(!ret.contains(s))
  36.                 ret += s + " ";
  37.         }
  38.     }
  39.     if(ret.compareTo("") == 0)
  40.         return null;
  41.     return ret;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement