react hook form validate email
import React from "react";
import { useForm } from "react-hook-form";
const Example = () => {
const { handleSubmit, register, errors } = useForm();
const onSubmit = values => console.log(values);
return (
<form onSubmit={handleSubmit(onSubmit)}>
<input
name="email"
ref={register({
required: "Required",
pattern: {
value: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i,
message: "invalid email address"
}
})}
/>
{errors.email && errors.email.message}
<input
name="username"
ref={register({
validate: value => value !== "admin" || "Nice try!"
})}
/>
{errors.username && errors.username.message}
<button type="submit">Submit</button>
</form>
);
};
react hook form
Also in JavaScript:
- discord.js clear code
- nodejs connection to localhost refused mysql errno -61
- angular material theme colors
- string interpolation
- nodejs print
- create a json object in javascript
- jquery add disabled to button
- is undefined javascript
- alert jquery
- Js Swiper
- react native text input number only
- appendchild element once if element presense in js
- nodemon : The term 'nodemon' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + nodemon index
- async await javascript
- nested array loop in javascript
- create dynamic fields in react
- Math.ceil
- vue-resource patch
- dom element get attribute
- react createElement interactive button
- hide and show in angular 8
- share data between livewire and alpine js
- node lodash documentation
- check data type in js