출처: http://pikac.tistory.com/169 [pikac]
// 영문만 허용 (숫자 포함)
protected InputFilter filter= new InputFilter() {
public CharSequence filter(CharSequence source, int start, int end,
Spanned dest, int dstart, int dend) {
Pattern ps = Pattern.compile("^[a-zA-Z0-9]+$");
if (!ps.matcher(source).matches()) {
return "";
}
return null;
}
};
// 한글만 허용
public InputFilter filterKor = new InputFilter() {
public CharSequence filter(CharSequence source, int start, int end,
Spanned dest, nt dstart, int dend) {
Pattern ps = Pattern.compile("^[ㄱ-가-힣]+$");
if (!ps.matcher(source).matches()) {
return "";
}
return null;
}
};
abcd.(EditText) findViewById(R.id.abcd);
abcd.setFilters(new InputFilter[] {filter});