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

react hook form validation controller

              rules={{
                required: {
                  value: required,
                  message: 'This field is required',
                },
                validate: {
                  fileType: (file) =>
                    !required ||
                    validFileTypes.indexOf(file.type) != -1 ||
                    'We only support (pdf, doc, docx, txt, rtf)',
                },
              }}
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript remove object key 
Javascript :: jquery grab table row 
Javascript :: accèder data-id javascript 
Javascript :: javascript sleep 1 second” is a pretty common code problem that people search ;-) 
Javascript :: code that will execute at a certain day and time javascript 
Javascript :: dynamic navigation with subitems 
Javascript :: window.cookies javascript 
Javascript :: Lodash.chunk chunk 
Javascript :: get the last array element javascript 
Javascript :: access variable from another function javascript 
Javascript :: regex not something 
Javascript :: require mongoose 
Javascript :: round to decimal javascript 
Javascript :: router in next js 
Javascript :: react bootstrap cdn 
Javascript :: use these instead of a for loop javascript 
Javascript :: javascript every 
Javascript :: javascript The toString() Method 
Javascript :: javascript form validation 
Javascript :: how to get input name in javascript 
Javascript :: unshift method in javascript 
Javascript :: get console javascript 
Javascript :: javascript capitalize all letters 
Javascript :: get last character of string javascript 
Javascript :: await is only valid in async function 
Javascript :: how to print every second in javascript 
Javascript :: jquery sum table column td 
Javascript :: image view component react js 
Javascript :: how to export a function in nodejs 
Javascript :: how to create thumbnail image from video in javascript 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =