Hello, I am currently working on a React Native app where users input their date using TextInput. As the user types, I would like to automatically format the date as MM/DD/YYYY. Here is the function I have created so far:
const formatDate(value: string) => {
if(!value) return '';
if(value.lastIndexOf('/') !== -1) {
value = value.substring(0, value.length-1);
} else if(value.length === 2 || value.length === 5)
{
value += '/';
}
return value;
}
The function works well when entering values but encounters issues when a user tries to delete characters from the date. The problem arises when attempting to delete a character. Any assistance or recommendations would be greatly appreciated.