Created
October 10, 2017 09:40
-
-
Save jie-meng/b648810bdb2045f7c094c2f2f9cfaed2 to your computer and use it in GitHub Desktop.
EditText input filter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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