react-form-inputs-validator
v1.0.2
Published
React library for easy form validation
Downloads
16
Maintainers
Readme
react-form-inputs-validator
React library for easy form validation.
##Install
npm install react-form-inputs-validator --save-dev
Demo
https://kubax2000.github.io/react-form-inputs-validator/
Usage
import React from 'react';
import useValidator from 'react-form-inputs-validator';
function SignInForm() {
const { inputs, Validator } = useValidator({
Email: "",
Password: "",
});
const handleFormSubmit = () => {
alert(JSON.stringify(inputs));
};
return (
<div>
<input {...Validator.importInput("Email")} />
<Validator.Required for="Email">This field is required.</Validator.Required>
<Validator.IsEmail for="Email">This field must be email.</Validator.IsEmail>
<input {...Validator.importInput("Password")} />
<Validator.Required for="Password">This field is required.</Validator.Required>
<input
type="submit"
value="Sign In"
{...Validator.importSubmit({ onSuccess: handleFormSubmit })}
/>
</div>
);
}
export default SignInForm;