javaandroidmatcheditview

Android EditText check if text match requested


I have a EditText in my application that i need to check if the text is like,

##-##-##

the "#" can be letters or numbers in groups of 2, how can i do that?


Solution

  • You can use this regex:-

    String regex = "[a-zA-Z0-9]{2}-{1}[a-zA-Z0-9]{2}-{1}[a-zA-Z0-9]{2}";
    System.out.println(str.matches(regex));