How to make useform validation in phoneInput filed from react-phone-input-2

Forums ReactHow to make useform validation in phoneInput filed from react-phone-input-2
Staff asked 3 years ago

Answers (1)

Add Answer
Umang Ramani Marked As Accepted
Staff answered 3 years ago

Using Controller from react-hook-form

like this

<Controller
name="phoneNumber"
control={control}
{
...register("phoneNumber", {
required: true
})
}
render={({ field: { onChange, value } }) => (

<PhoneInput
name="phoneNumber"
value={value}
onChange={(e, data) => {
onChange(e);
}}
defaultCountry="TH"
autoFormat
countryCodeEditable
id="phone-input"
/>
)}
/>

 

Subscribe

Select Categories