📦 Valdation Box
Guide

Quick Start Guide

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.

import { validateUsername } from "validation-box";

Instead of returning a simple boolean, functions now return an object containing valid and errors.

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."] }
The default validation rules apply if no options are provided.

On this page