$validator
Updated on Aug 19, 2025 4 minutes to readThe Validator Plugin provides methods for creating and applying validation rules to input data.
It supports built-in validators (string, number, regex, in, callback, etc.) and allows custom error messages and logic.
Properties
| Property | Description | 
|---|---|
| V_BOOLEAN | Validates that the value is a boolean. | 
| V_CALLBACK | Validates using a custom callback. | 
| V_EMAIL | Validates that the value is a valid email address. | 
| V_IN | Validates that the value is among a set of allowed values. | 
| V_NUMBER | Validates that the value is a number. | 
| V_PASSWORD | Validates that the value meets password strength requirements. | 
| V_REGEX | Validates that the value matches a regular expression. | 
| V_REQUIRED | Validates that the value is not empty. | 
| V_STRING | Validates that the value is a string. | 
Methods
| Method | Description | 
|---|---|
| create | Creates a new Validator instance. | 
Methods Details
create()
• Type
(data: object, labels?: object) => Validator
                    🔽 Show more
                
 
            • Details
Expects a data object and an optional labels object (default: {}).
Returns a Validator instance that can be used to define and apply validation rules.
• Example
// Create a validator with input data
const validator = E8App.$validator.create(
    {
        username: 'john_doe',
        age: 17,
        email: 'not-an-email',
        password: 'abc123'
    },
    {
        username: 'User Name',
        age: 'Age',
        email: 'Email',
        password: 'Password'
    }
);
// Add validation rules
validator
    // String: username between 3 and 20 characters
    .addRule('username', E8App.$validator.V_STRING, { min: 3, max: 20 })
    // Number: age must be at least 18
    .addRule('age', E8App.$validator.V_NUMBER, { min: 18 })
    // Email validation
    .addRule('email', E8App.$validator.V_EMAIL)
    // Callback: password must contain at least one uppercase letter
    .addRule('password', 'callback', {
        callback: (value) => /[A-Z]/.test(value),
        message: 'Password must contain at least one uppercase letter'
    });
// Run validation
const isValid = validator.validate();
// isValid will be false because "age" < 18, "email" is invalid, and "password" has no uppercase letter
const errors = validator.getErrors();
// errors → [
//   "Age must be at least 18",
//   "Email is not a valid address",
//   "Password must contain at least one uppercase letter"
// ]
// Example usage: display errors in UI or return in API response
// errors variable contains the array of validation messages
                    🔽 Show more