Can't you make EditText only accept certain characters?

Asked 1 years ago, Updated 1 years ago, 73 views

I even put up EditText, but I want to make sure that only Korean is entered when I receive it. How shall I do it?

android edittext

2022-09-22 16:56

1 Answers

You can use InputFilter to change it to regular expressions so that only Korean is input.

// So that only Korean is entered
public InputFilter filterAlphaNum = new InputFilter() {
    public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
        Patterns = Pattern.compile ("^[-가--he]*$"); 
        if (!ps.matcher(source).matches()) { 
            return ""; 
        } 
        return null; 
    } 
}; 

// Apply to EditText as follows.
editText.setFilters(new InputFilter[]{filterAlphaNum}); 

//You only need to change the regular expression from the source below.
Pattern ps = Pattern.compile("^[a-zA-Z0-9]*$"); 

To enter only Korean: "[-가-hehe]*$" For English only: "[a-zA-Z]*$" Only numbers are entered: "[0-9]*$"

[-가--he]*$"[a-zA-Z]*$"[0-9]*$"

If you want only English and numeric characters to be entered, you can enter "[a-zA-Z0-9]*$".

[a-zA-Z0-9]*$"


2022-09-22 16:56

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.