Hello i working on a react native app where a user enters their date via Textinput but as the user types i would like to format the date to MM/DD/YYYY. So far i have this function
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}
It work fines when entering values and not deleting. But if a user attempts to delete their date it works incorrectly. My issue is when a user attempts to delete a character. Any help or guidance would be appreciated.