A versatile form data validation library offering a fluent API to ensure data integrity and consistency in web applications. Please note that this project is currently a work in progress and undergoing active development.
- Fluent validation API
- Supports basic input types: boolean, date, number and string.
- Array validation using
[]
and.*
notations - Customizable validation rules
- Framework agnostic
- With 40+ available rules
To install, use your preferred package manager:
npm install fluent-formdata-validator
Detailed instructions on getting started and list of available validation rules can be found in the documentation.
import { Rule, Validation } from '@sveltecult/formdata-validator';
/** @type {import('./$types').Actions} */
export const actions = {
default: async ({ request }) => {
const formData = await request.formData();
const validation = new Validation(formData, {
email: Rule.string().required().email(),
password: Rule.string().required().minLength(8).confirmed()
});
const errors = await validation.errors();
if (errors.any() === true) {
console.log(errors.all());
}
}
};
This library allows writing custom validation logic using the .custom()
rule for scenarios where standard validation rules don't meet specific requirements, such as database-related checks. Click here to learn more about how to create your own custom validation.
This library is licensed under the MIT License.