How to allow only numbers in textbox
in reactjs
using regular expression
only?
I know you've asked for regular expression.
But here is a solution without regex if anyone wants.
const handlePincode = (e) => {
!isNaN(e.nativeEvent?.data) && setPincode(e.currentTarget.value);
};
return (
);
The event.nativeEvent.data
gives me the currently typed value, I can just validate that and set the event.currentTarget.value
or just return it.