public DateEditText(Context context) {
super(context);
setupFilter();
}
private void setupFilter(){
InputFilter[] filters = new InputFilter[1];
filters[0] = new InputFilter() {
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
if (end > start) {
String destTxt = dest.toString();
String resultingTxt = destTxt.substring(0, dstart) + source.subSequence(start, end) + destTxt.substring(dend);
Log.d("InputFilter",resultingTxt);
if (!resultingTxt.matches("^(\\d{0,2}|\\d{2}/** regex para tu ingreso **{1}\\d{0,2}|\\d{2}/{1}\\d{2}/{1}\\d{0,4})$")) {
if (source instanceof Spanned) {
SpannableString sp = new SpannableString("");
return sp;
} else {
return "";
}
}
}
return null;
}
};
this.getEditText().setFilters(filters);
}
agregado y corregido
matches("^(\d\\d{0,2}|\d|\\d{2}\\\/{1}\d\\d{0,2}|\d|\\d{2}\\\/{1}\d\\d{2}\\\/{1}\d\\d{0,4})"$");