Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

react hook form validation

import React from "react";
import { useForm } from "react-hook-form";

export default function App() {
  const { register, handleSubmit } = useForm();
  const onSubmit = data => console.log(data);
   
  return (
    <form onSubmit={handleSubmit(onSubmit)}>
      <input {...register("firstName", { required: true, maxLength: 20 })} />
      <input {...register("lastName", { pattern: /^[A-Za-z]+$/i })} />
      <input type="number" {...register("age", { min: 18, max: 99 })} />
      <input type="submit" />
    </form>
  );
}
Comment

react-hook-form file validation

 required: {
          value: true,
          message: "Product image is required.",
        },
      validate: {
        lessThan10MB: (files) => files[0]?.size < 10000000 || "Max 10MB",
        acceptedFormats: (files) =>
          ["image/jpeg", "image/png", "image/gif"].includes(files[0]?.type) ||
          "Only PNG, JPEG e GIF",
      },
Comment

PREVIOUS NEXT
Code Example
Javascript :: react router 6 multiple routes layout 
Javascript :: condition inner populate mongoose 
Javascript :: check for string anagram javascript 
Javascript :: react native image 
Javascript :: javascript add event listenner for multiple events 
Javascript :: check in node whether the port is working or not 
Javascript :: react hook form validation 
Javascript :: get color from classname 
Javascript :: code that will execute at a certain day and time javascript 
Javascript :: getserversideprops nextjs 
Javascript :: regex quantifiers 
Javascript :: rock paper scissors javascript 
Javascript :: hashset in javascript 
Javascript :: next-auth with linkedin provider 
Javascript :: change js 
Javascript :: router in next js 
Javascript :: how to draw a horizontal line in javascript 
Javascript :: react router cannot read location of undefined 
Javascript :: react native meter 
Javascript :: reflect javascript 
Javascript :: javascript play audio from buffer 
Javascript :: jquery get tr value 
Javascript :: arry to object using reduce 
Javascript :: mongoose db connect 
Javascript :: how to add to an array js 
Javascript :: angular create library 
Javascript :: images not displaying in react 
Javascript :: javascript print array 
Javascript :: javascript date format dd-mm-yyyy 
Javascript :: chai test throw error 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =