Validation comes in two varieties. Back end (or server-side) to check that everything sent by the client is good and front end (or client-side) to check on things before anything is sent. While both necessary, client-side validation leads to significantly improved user experience without the overhead of going back and forth with a server.
calidation is a library that aids in client-side form validation by providing a component that you can wrap your forms in. This component accepts a configuration with your validation rules and accepts a function as a child that contains the field values, any errors and whether or not the form is valid.
To get started, add calidation
to your project with npm
or yarn
:
Via npm:
With calidation
added to our project, we can put together a simple login form with ease!
The library even takes care of checking the input as it is entered without any additional event handlers written by us.
Coming from the land of validator and debouncing change events for each input, this approach is a breath of fresh air.
The login form example is really just the tip of the iceberg as the calidation
library provides so much more than the few validation methods we utilized. It even supports rolling your own validation methods and conditional rules!
Here’s a full list of validation methods you get out of the box:
More advanced topics like rolling your own “calidator” and conditional validation logic are very well documented by the library’s author.
And for a live demo of our login component from earlier, you can check out this CodeSandbox.
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
While we believe that this content benefits our community, we have not yet thoroughly reviewed it. If you have any suggestions for improvements, please let us know by clicking the “report an issue“ button at the bottom of the tutorial.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!