Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

Format date as user types to MM/DD/YYYY in typescript

$
0
0

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.


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>