Check if string only contains a-z, A-Z and 0-9, length is between 2 and 25 - Android java.util.regex

Android examples for java.util.regex:Character Pattern

Description

Check if string only contains a-z, A-Z and 0-9, length is between 2 and 25

Demo Code

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {

  public final static boolean isValidCharacter(String txtInput) {
    Pattern pattern;// w w  w.j a v  a 2  s . c  o m
    Matcher matcher;

    final String USERNAME_PATTERN = "^[a-z0-9A-Z]{2,25}$";
    pattern = Pattern.compile(USERNAME_PATTERN);

    matcher = pattern.matcher(txtInput);
    return matcher.matches();
  }

}

Related Tutorials