Skip to content

Instantly share code, notes, and snippets.

@hasankucuk
Created April 13, 2018 11:45
Show Gist options
  • Save hasankucuk/4afc0a6abb8bcd53af1ea56c80d24973 to your computer and use it in GitHub Desktop.
Save hasankucuk/4afc0a6abb8bcd53af1ea56c80d24973 to your computer and use it in GitHub Desktop.
To make / between expiration month and year
mEdtPaymentAuthorCreditExpirationDate.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
mLength = mEdtPaymentAuthorCreditExpirationDate.getText().length();
}
@Override
public void onTextChanged(CharSequence charSequence, int start, int before, int count) {
int currentLength = mEdtPaymentAuthorCreditExpirationDate.getText().length();
boolean ignoreBecauseIsDeleting = false;
if (mLength > currentLength) {
ignoreBecauseIsDeleting = true;
}
if (ignoreBecauseIsDeleting) {
return;
}
if (charSequence.length() == 2 && !charSequence.toString().contains("/")) {
String cleanString = charSequence.toString().replaceAll("[/,.]", "");
mEdtPaymentAuthorCreditExpirationDate.setText(cleanString + " / ");
mEdtPaymentAuthorCreditExpirationDate.setSelection(charSequence.length() + 3);
mEdtPaymentAuthorCreditExpirationDate.addTextChangedListener(this);
}
}
@Override
public void afterTextChanged(Editable editable) {
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment