I do not fully understand how I can implement the function of checking the login for the presence in it of only numbers and Latin letters of upper and lower case. I.e

private boolean Checking_Login(String in_login) { final char alf_number[] = {'0','1','2','3','4','5','6','7','8','9','a','b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z','A','B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'}; boolean flag = false; for(int i=0; i<in_login.length(); i++) { for(int j=0; j<alf_number.length; j++) { if(in_login.charAt(i) == alf_number[j]) { flag = true; break; } if(!flag) return flag; } } return flag; } 

    1 answer 1

    You can make regex, I think it will be more logical and easier

     String template = "([0-9A-Za-z])"; public boolean isMatchingRegexp(final String text, final String template) { Pattern pattern = null; try { pattern = Pattern.compile(template); } catch(PatternSyntaxException e) { e.printStackTrace(); } if(pattern == null) { return false; } final Matcher regexp = pattern.matcher(text); return regexp.matches(); } 
    • String template = "([0-9A-Za-z]))"; extra bracket - Nikola Krivosheya
    • I apologize, fixed - GenCloud