umotif/php-livr-extra

Lightweight validator supporting Language Independent Validation Rules Specification (LIVR)

1.0.0 2020-12-10 12:30 UTC

This package is auto-updated.

Last update: 2024-04-07 22:45:26 UTC


README

Extension wrapper for umotif-public/php-validator-livr.

This library contains additional LIVR rules not found in the original uMotif package.

Installation

Add the package via composer:

composer require umotif/php-livr-extra

Usage

LIVR documentation can be found here.

New Rules Functionality

This library contains the following new rules:

###list_length

(Based on js-livr-extra-rules)

Checks that the value is a list and it contains required number of elements. You can pass exact number of elements required or a range.

Do not forget about "required" rule if you want the field to be required.

Example:

{
    list1: ['required', { list_length: 10 }]; // List is required and should contain exactly 10 items,
    list2: {
        list_length: 10;
    } // List is not required but if it is present, it should contain exactly 10 items
    list3: {
        list_length: [3, 10];
    } // List is not required but if it is present, it should has from 3 to 10 items
}

Error codes: 'FORMAT_ERROR', 'TOO_FEW_ITEMS', 'TOO_MANY_\ITEMS'

Tests

To run all tests, enter php ./vendor/bin/phpunit --verbose.