Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

insert isValidPhoneNumber in react hook form

import { useForm, Controller } from 'react-hook-form'
import PhoneInput, { isValidPhoneNumber } from 'react-phone-number-input'

import 'react-phone-number-input/style.css'

const MyForm = () => {
  const {
    handleSubmit,
    formState: { errors },
    control,
  } = useForm()

  const onSubmit = (data) => {
    console.log(data)
  }

  return (
    <form onSubmit={handleSubmit(onSubmit)} className="user-info-form">
      <div>
        <label htmlFor="phone-input">Phone Number</label>
        <Controller
          name="phone-input"
          control={control}
          rules={{ required: true }}
          render={({ field: { onChange, value } }) => (
            <PhoneInput
              value={value}
              onChange={onChange}
              defaultCountry="TH"
              id="phone-input"
            />
          )}
        />
        {errors.phone && <p className="error-message">Invalid Phone</p>}
      </div>
    </form>
  )
}

export default MyForm
Comment

PREVIOUS NEXT
Code Example
Javascript :: jquery syntax 
Javascript :: javascript add parameter to object 
Javascript :: jquery call a class 
Javascript :: middleware in node js 
Javascript :: how to deploy firebase angular 10 
Javascript :: react route multiple components 
Javascript :: npm install --save react-draft-wysiwyg draft-js react-draft-wysiwyg-a 
Javascript :: get all files in directory recursively nodejs 
Javascript :: js string to arraybuffer 
Javascript :: jquery label with text 
Javascript :: attr.disabled not working in angular 
Javascript :: generate unique random number in javascript 
Javascript :: node settimeout 
Javascript :: javascript sort 
Javascript :: format iso time in human readable format with moment js 
Javascript :: back button event listener javascript 
Javascript :: angular multiselect dropdown 
Javascript :: module.exports in js 
Javascript :: how to upload file with button react 
Javascript :: scroll up link 
Javascript :: use of this keyword in js 
Javascript :: javascript integer to binary 
Javascript :: javascript floating point addition 
Javascript :: concat js 
Javascript :: template literals 
Javascript :: redirect to dashboard after login in vue 
Javascript :: trash alternate outline icon not coming to right side react 
Javascript :: js how to have an onclick inside of another onClick 
Javascript :: getelementbyclassname get multiple class 
Javascript :: convert a signed 64.64 bit fixed point number online 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =