Skip to content

Instantly share code, notes, and snippets.

@jie-meng
Created October 10, 2017 09:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jie-meng/b648810bdb2045f7c094c2f2f9cfaed2 to your computer and use it in GitHub Desktop.
Save jie-meng/b648810bdb2045f7c094c2f2f9cfaed2 to your computer and use it in GitHub Desktop.
EditText input filter
editText.setFilters(new InputFilter[] {
new InputFilter() {
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
if (!somePattern.matcher(source).matches()) {
//return empty to refuse
return "";
} else {
//return null if accept
return null;
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment