I want to make pattern text input for months and years. So, I made some logic but it’s not working.
Below is the code:
const [monthYear, setMonthYear] = useState(null)
function _handlingMonthYear(number) {
setMonthYear(number.replace(/s?/g, '').replace(/(d{2})/g, '$1 ').trim());
}
<TextInput
onChangeText={(text) => _handlingMonthYear(text)}
placeholder='MM/YY'
value={monthYear}
/>
I want to make that if the user type 1234 then it should appear as 12/34 in TextInput.
2
Answers
I found this solution for the format look like as 'MM/YY'.
Below is the full code of my solution. It's working.
you can use this regular expression