180
rated 0 times
[
184]
[
4]
/ answers: 1 / hits: 5436
/ 3 Years ago, fri, april 9, 2021, 12:00:00
I'm trying to set up a phone number input in react-hook-form
library.
I set input type to number, but it still accepts "e" and "-" chars.
I tried to prevent it like this:
<Controller
name="phone"
control={control}
rules={{ required: true }}
render={({ onChange, value, ref }) => (
<Input
ref={ref}
type="number"
label="phone"
onChange={(e) =>
/[^e]/.test(e.target.value) && onChange(e.target.value)
}
val={value}
/>
But it doesn't work properly.
Any recommendations how to solve this problem?
More From » reactjs