CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-vuelidate--validators

Comprehensive validation library for Vue.js applications providing common validators with built-in error messages and customization options

87

1.14x
Overview
Eval results
Files

core-validators.mddocs/

Core Validators

Essential validation functions for common form validation scenarios including required fields, string/numeric format validation, and length constraints.

Capabilities

Required Field Validation

Validates that a field is not empty, null, or undefined.

/**
 * Validates that a field has a value (not empty, null, or undefined)
 * @returns ValidationRuleWithoutParams that returns true if field has value
 */
const required: ValidationRuleWithoutParams;

Usage Examples:

import { required } from "@vuelidate/validators";

// The validators are validation objects with $validator, $message, and $params
const requiredValidator = required;

// In validation rules (most common usage)
const validationRules = {
  username: { required },
  email: { required }
};

// Direct validator usage (testing the internal validator function)
const isValid = requiredValidator.$validator("hello"); // true  
const isEmpty = requiredValidator.$validator(""); // false
const isNull = requiredValidator.$validator(null); // false

String Format Validators

Validators for checking string content patterns and character types.

Alpha Validator

Validates that a string contains only alphabetic characters.

/**
 * Validates that string contains only alphabetic characters (a-z, A-Z)
 * @returns ValidationRuleWithoutParams that returns true if string is alphabetic
 */
const alpha: ValidationRuleWithoutParams;

Alphanumeric Validator

Validates that a string contains only alphanumeric characters.

/**
 * Validates that string contains only alphanumeric characters (a-z, A-Z, 0-9)
 * @returns ValidationRuleWithoutParams that returns true if string is alphanumeric
 */
const alphaNum: ValidationRuleWithoutParams;

Numeric Validator

Validates that a string contains only numeric characters.

/**
 * Validates that string contains only numeric characters (0-9)
 * @returns ValidationRuleWithoutParams that returns true if string is numeric
 */
const numeric: ValidationRuleWithoutParams;

Usage Examples:

import { alpha, alphaNum, numeric } from "@vuelidate/validators";

// In validation rules (most common usage)
const validationRules = {
  firstName: { alpha },
  username: { alphaNum },
  zipCode: { numeric }
};

// Direct validator function usage
const alphaValidator = alpha;
const isAlpha = alphaValidator.$validator("Hello"); // true
const notAlpha = alphaValidator.$validator("Hello123"); // false

const alphaNumValidator = alphaNum;
const isAlphaNum = alphaNumValidator.$validator("Hello123"); // true
const notAlphaNum = alphaNumValidator.$validator("Hello-123"); // false

const numericValidator = numeric;
const isNumeric = numericValidator.$validator("12345"); // true
const notNumeric = numericValidator.$validator("123abc"); // false

Number Format Validators

Validators for specific numeric formats and patterns.

Decimal Validator

Validates that a value is a valid decimal number.

/**
 * Validates that value is a valid decimal number
 * @returns ValidationRuleWithoutParams that returns true if value is decimal
 */
const decimal: ValidationRuleWithoutParams;

Integer Validator

Validates that a value is a valid integer.

/**
 * Validates that value is a valid integer
 * @returns ValidationRuleWithoutParams that returns true if value is integer
 */
const integer: ValidationRuleWithoutParams;

Usage Examples:

import { decimal, integer } from "@vuelidate/validators";

// In validation rules (most common usage)
const validationRules = {
  price: { decimal },
  quantity: { integer }
};

// Direct validator function usage
const decimalValidator = decimal;
const isDecimal = decimalValidator.$validator("123.45"); // true
const notDecimal = decimalValidator.$validator("abc"); // false

const integerValidator = integer;
const isInteger = integerValidator.$validator("123"); // true
const notInteger = integerValidator.$validator("123.45"); // false

Length Constraint Validators

Validators for enforcing minimum and maximum length requirements on strings, arrays, and objects.

Minimum Length Validator

Validates that a value meets a minimum length requirement.

/**
 * Validates that value meets minimum length requirement
 * @param min - Minimum length (number or Vue ref)
 * @returns ValidationRuleWithParams with min parameter
 */
function minLength(min: number | Ref<number>): ValidationRuleWithParams<{ min: number }>;

Maximum Length Validator

Validates that a value does not exceed a maximum length.

/**
 * Validates that value does not exceed maximum length
 * @param max - Maximum length (number or Vue ref)
 * @returns ValidationRuleWithParams with max parameter
 */
function maxLength(max: number | Ref<number>): ValidationRuleWithParams<{ max: number }>;

Usage Examples:

import { minLength, maxLength } from "@vuelidate/validators";
import { ref } from "vue";

// In validation rules (most common usage)
const validationRules = {
  username: { minLength: minLength(3) },
  title: { maxLength: maxLength(100) }
};

// Direct validator function usage for testing
const minLengthValidator = minLength(3);
const hasMinLength = minLengthValidator.$validator("hello"); // true (5 >= 3)
const tooShort = minLengthValidator.$validator("hi"); // false (2 < 3)

const maxLengthValidator = maxLength(10);
const withinMaxLength = maxLengthValidator.$validator("hello"); // true (5 <= 10)
const tooLong = maxLengthValidator.$validator("very long text"); // false (14 > 10)

// Reactive length validation with Vue refs
const minRef = ref(5);
const dynamicMinLength = minLength(minRef);

// Array length validation
const arrayLengthValidator = minLength(2);
const arrayValid = arrayLengthValidator.$validator(["item1", "item2"]); // true

Value Constraint Validators

Validators for enforcing minimum and maximum value requirements on numbers.

Minimum Value Validator

Validates that a numeric value meets a minimum requirement.

/**
 * Validates that numeric value meets minimum requirement
 * @param min - Minimum value (number, string, or Vue ref)
 * @returns ValidationRuleWithParams with min parameter
 */
function minValue(min: number | Ref<number> | string | Ref<string>): ValidationRuleWithParams<{ min: number }>;

Maximum Value Validator

Validates that a numeric value does not exceed a maximum.

/**
 * Validates that numeric value does not exceed maximum
 * @param max - Maximum value (number, string, or Vue ref)
 * @returns ValidationRuleWithParams with max parameter
 */
function maxValue(max: number | Ref<number> | string | Ref<string>): ValidationRuleWithParams<{ max: number }>;

Between Validator

Validates that a numeric value is within a specified range.

/**
 * Validates that numeric value is between min and max (inclusive)
 * @param min - Minimum value (number or Vue ref)
 * @param max - Maximum value (number or Vue ref)
 * @returns ValidationRuleWithParams with min and max parameters
 */
function between(min: number | Ref<number>, max: number | Ref<number>): ValidationRuleWithParams<{ min: number, max: number }>;

Usage Examples:

import { minValue, maxValue, between } from "@vuelidate/validators";
import { ref } from "vue";

// In validation rules (most common usage)
const validationRules = {
  age: { minValue: minValue(18) },
  score: { maxValue: maxValue(100) },
  percentage: { between: between(0, 100) }
};

// Direct validator function usage for testing
const minValueValidator = minValue(18);
const aboveMin = minValueValidator.$validator(25); // true (25 >= 18)
const belowMin = minValueValidator.$validator(15); // false (15 < 18)

const maxValueValidator = maxValue(100);
const belowMax = maxValueValidator.$validator(75); // true (75 <= 100)
const aboveMax = maxValueValidator.$validator(150); // false (150 > 100)

const betweenValidator = between(18, 65);
const inRange = betweenValidator.$validator(30); // true (18 <= 30 <= 65)
const outOfRange = betweenValidator.$validator(70); // false (70 > 65)

// Reactive value validation
const minAge = ref(21);
const dynamicMinValue = minValue(minAge);

// String number validation
const stringMinValue = minValue("18");
const stringValue = stringMinValue.$validator("25"); // true (parses strings to numbers)

Install with Tessl CLI

npx tessl i tessl/npm-vuelidate--validators

docs

conditional-validators.md

core-validators.md

format-validators.md

helpers-utilities.md

index.md

internationalization.md

logical-operators.md

tile.json