Created
May 23, 2020 10:51
-
-
Save Gauthamjm007/692f46a93b563bea80bba804bca9bd25 to your computer and use it in GitHub Desktop.
React hooks form ,login component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import { useForm } from "react-hook-form"; | |
const Login = () => { | |
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,4}$/i, | |
message: "invalid email address", | |
}, | |
})} | |
/> | |
{errors.email && errors.email.message} | |
<input | |
name="password" | |
ref={register({ | |
required: "Required", | |
pattern: { | |
value: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$/i, | |
message: "Minimum eight characters, at least one uppercase letter, one lowercase letter and one number", | |
}, | |
})} | |
/> | |
{errors.password && errors.password.message} | |
<button type="submit">Submit</button> | |
</form> | |
); | |
}; | |
export default Login; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment