@OnTextChanged(value = R.id.credit_card_number, callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED)
void onTextChanged(Editable text) {
int length = text.length();
int lastIndex = length - 1;
InputFilter[] filters = text.getFilters();
// Disable input filters
text.setFilters(new InputFilter[] {});
if (length > 0) {
if (TextUtils.lastIndexOf(text, '-') != lastIndex && length % 5 == 0) {
text.insert(lastIndex, mContext.getString(R.string.dash));
} else {
text.delete(lastIndex, lastIndex);
}
}
}
According to the current scenario I can generate the following string pattern. 1234-4564-5676 But issue is that if I tried to enter a value in between numbers my format get break.as a example 12534-4564-5676 What I need to make 1253-4456-4567-6.
Is there any possible way to do that with minimal changes? Thank in advance.