Lightweight package which helps in implementing simple and generic form validations.
npm install @brocode/simple-react-form-validation-helpernpm i @brocode/simple-react-form-validation-helper
onChange and onBlur events of your input fields.
jsx
// import validator
import validator from "@brocode/simple-react-form-validation-helper";
const sampleForm = () => {
// use states to store the input value and error message
const [email, setEmail] = useState("");
const [emailError, setEmailError] = useState("");
return (
<>
{/ Inside your form /}
type="email"
value={email}
onChange={(e) => {
setEmail(e.target.value);
validator.emailInputChangeHandler(e.target.value, setEmailError);
}}
onBlur={(e) => {
validator.emailInputBlurHandler(e.target.value, setEmailError);
}}
/>
{/ Your error message goes here /}
{emailError}
>
);
};
export default sampleForm;
`
---- Validator types ----
- Name
- Phone Number
- Email
- Password
- Address
- Postal-code
- Price
- Percentage
Note: _Use input_ type="text"` _of while validating phone number, postal-code and percentage._