Octavalidate - ReactJS is a react form validation library that helps you validate your react forms.
It is very easy to implement and offers a wide range of validation rules.
INSTALL OCTAVALIDATE
To use this library, you have to install it in your project through NPM.
If you wish to visit this package on NPM, click on the button below.
Visit packageOnce the package has been installed, follow the process below to setup validation on your form;
- Import the module
- Create a login component
- Within your component, create a function that will handle form submission
- Initialize the library within this function.
- Now invoke the
validate()
method - When you have setup the call back function, return the form
Import the module at the top of your React page
Create a component for the page
Within this component, create a function that will handle form submission
Now initialize the library within this function.
Make sure that the id used to initialize this library is the same as the form itself.
Once you have initialized the library, invoke the validate()
method on the validation instance to begin validation on the form
The return type of validate()
method is Boolean
- true means there are no validation errors
- false means there are validation errors
This means that if the validate()
method returns true, we are free to process the form.
Here's the full code
login.js
If you look at the code above, you will notice that a form was returned from the component.
This form has an ID that is equal to the one used to initialize the validation instance.
This form also has inputs with the attribute octavalidate. This attribute contains the validation rules that will be used to validate that particular form input. Read more on validation rules here
Here are some things to note when setting up form validation using this library;
- Make sure the a form ID exists on the form and the input element IDs are unique!
- Make sure to initialize the validation library within the callback function that handles form submission!
DEMO
Would you like to see a simple implementation of this library on a react project? Click the button below to visit the repository
Vist repo