UNPKG

validation-box

Version:

The only validation library - with flexible regex - you need.

38 lines (28 loc) 1.33 kB
--- title: Quick Start Guide description: This guide will help you quickly understand how to use Validation Box, configure it to fit your needs, and troubleshoot any potential issues. --- ## Basic Usage Example Once installed, you can start using Validation Box right away. Here's a simple example of validating a username with custom rules: First hand you need to do the import from the library and call the function you are using. [Here the list of options](https://vbox.euotiniel.com/docs/configuration/configuration). ```ts import { validateUsername } from "validation-box"; ``` Instead of returning a simple boolean, functions now return an object containing valid and errors. ```ts import { validateUsername } from "validation-box"; const result = validateUsername("dev_otoniel", { min: 5, max: 15, allowSpecialChars: "_-", bannedWords: ["admin", "root"], messages: { min: "Username must be at least 5 characters long.", max: "Username cannot exceed 15 characters.", bannedWords: "Username cannot contain restricted words.", } }); console.log(result.valid); // true or false console.log(result.errors); // { username: ["Username must be at least 5 characters long."] } ``` <Callout>The default validation rules apply if no options are provided.</Callout>