I have a date formatter that takes in String input from a text field. It formats correctly. However, I am unable to delete the first "/" it keeps 3 strings in UI when using the keyboard delete. I am able to delete the second "/". Any idea why this is happening?
internal class DateFormatter {
override fun format(input: String): String {
val cleanInput = input.replace("/", "")
val textLength = cleanInput.length
var result = ""
result = if (textLength >= 2 && textLength < 4) {
cleanInput.substring(0, 2) + "/" + cleanInput.substring(2)
} else if (textLength >= 5) {
(
cleanInput.substring(0, 2) +
"/" + cleanInput.substring(2, 4) + "/" +
cleanInput.substring(4)
).take(10)
} else if (input.last() == '/') {
input.substring(0, input.length - 1)
} else {
input
}
return result
}
}
textLength < 4andtextLength >= 5. What's supposed to happen when it's exactly 4?inputwhen this happens? What are you expecting it to return, what is it returning instead?