Luminova Framework

PHP Luminova: Input Validation Rules

Last updated: 2025-11-10 09:50:36

Comprehensive list of all built-in input validation rules in Luminova Framework, with parameters, usage examples, and detailed explanations for each rule type.

The Validation Rules reference lists all built-in rules available in the Luminova Input Validation Class.These rules help ensure that input data follows the correct format before being processed or saved.

Luminova’s validation system is built to be simple, predictable, and flexible.It supports numeric comparisons, string and format checks, file validation, and even custom logic through callbacks.

Each rule may accept parameters to refine how the validation behaves.For instance, the min(5) rule ensures the input value has a minimum length of 5 characters.


Applying Rules

You can define validation rules directly within your controller or service class:

$this->input->rules = [
  'email' => 'required|email',
  'username' => 'required|alphanumeric|min(3)|max(20)',
  'age' => 'required|between(18,50)',
];

Each field can contain one or more rules separated by a pipe |.Rules may also include parameters inside parentheses — for example, max(255) or between(10,100).


Customizing Messages

Each rule supports a default error message, but you can override them easily:

$this->input->messages = [
   'username' => [
      'required' => 'Please enter a username.',
      'alphanumeric' => 'Username can only contain letters and numbers.',
   ],
];

This allows you to make validation feedback more natural and user-friendly.


Passing Rule Arguments

Most rules in Luminova's input validation can accept optional or required arguments. These arguments are passed as strings and automatically converted to the correct data type internally, so validation works as expected.

How Rule Arguments Work

  1. Strings

    • 'rule("")' → Empty string
    • 'rule(Text)' → String "Text"
    • 'rule("Text")' → String "Text"
  2. NumbersNumbers are treated like strings initially, then converted for internal use:

    • 'rule(12345)' → Integers 12345
    • 'rule(0.5)' → Decimal number 0.5
    • 'rule(-10)' → Negative number -10
  3. Booleans

    • 'rule(true)' → Truthy true
    • 'rule(false)' → Falsy false
  4. Nulls

    • 'rule(null)' → Nulled null
    • 'rule()' → Default value or null null
  5. Arrays

    • 'rule([1, 2, 3])' → Array [1, 2, 3]
  6. Objects / JSON

    • 'rule({key: "value", id: 1})' → Object key-pair ['key' => 'value', 'id' => 1]
  7. Multiple ArgumentsYou can pass multiple arguments separated by commas:

    • 'rule([1, 2, 3], ["a", "b"])' → Multiple arrays [ [1, 2, 3], ["a", "b"] ]
    • 'rule({key: "A", id: 1}, {key: "B", id: 2})' → Multiple objects [ ['key'=>'A','id'=>1], ['key'=>'B','id'=>2] ]
  8. Mixed ArgumentsAny combination of types is allowed:

    • rule(1, true, null, [1,2,3], {key: "A", id: 1}, text)

Example Usage:

This rule ensures that the tags input only contains values from the specified array.

$this->input->rules = [
  'tags' => 'in_array([php, js, css, html], true)'
];

Rules

none

Ignores the field completely. It always passes, even if empty.Alias: nullable.

RuleParameterDescription
nonevoidSkips validation for the field.
$this->input->rules = [
   'middle_name' => 'none'
];

required

The field must be present and not empty.

RuleParameterDescription
requiredvoidMakes the field mandatory.
$this->input->rules = [
   'email' => 'required'
];

length

Requires the field string value to have an exact length.

RuleParameterDescription
length(length)intExact character length required.
$this->input->rules = [
   'username' => 'length(4)'
];

maxlength

Specifies the maximum allowed length for a string value.

RuleParameterDescription
maxlength(length)intMaximum number of characters allowed.
$this->input->rules = [
   'username' => 'maxlength(20)'
];

minlength

Specifies the minimum allowed length for a string value.

RuleParameterDescription
minlength(length)intMinimum number of characters required.
$this->input->rules = [
   'password' => 'minlength(8)'
];

limit

Requires a numeric value to match an exact value-limit.

RuleParameterDescription
limit(exact)int\|floatExact numeric value required.
$this->input->rules = [
   'age' => 'limit(30)'
];

maxlimit

Specifies the maximum allowed numeric value-limit.

RuleParameterDescription
maxlimit(limit)int\|floatMaximum numeric value allowed.
$this->input->rules = [
   'age' => 'maxlimit(50)'
];

minlimit

Specifies the minimum allowed numeric value-limit.

RuleParameterDescription
minlimit(offset)int\| floatMinimum numeric value required.
$this->input->rules = [
   'age' => 'minlimit(18)'
];

size

Requires an array to have an exact number of elements.

RuleParameterDescription
size(count)intExact array length required.
$this->input->rules = [
   'tags' => 'size(5)'
];

maxsize

Specifies the maximum allowed number of elements in an array.

RuleParameterDescription
maxsize(limit)intMaximum array length allowed.
$this->input->rules = [
   'tags' => 'maxsize(10)'
];

minsize

Specifies the minimum allowed number of elements in an array.

RuleParameterDescription
minsize(offset)intMinimum array length required.
$this->input->rules = [
   'tags' => 'minsize(2)'
];

max

Specifies the maximum allowed value for numeric values, string length, or array elements.

RuleParameterDescription
max(length)int\|floatMaximum value, string length, or array count.
$this->input->rules = [
   'age'      => 'max(40)',
   'tags'     => 'max(5)',
   'username' => 'max(20)'
];

min

Specifies the minimum allowed value for numeric values, string length, or array elements.

RuleParameterDescription
min(length)int\|floatMinimum value, string length, or array count.
$this->input->rules = [
   'age'      => 'min(18)',
   'tags'     => 'min(2)',
   'username' => 'min(5)'
];

fixed

Specifies the exact allowed value for numeric values, string length, or array elements.

RuleParameterDescription
fixed(length)int\|floatValue, string length, or array count must match exactly.
$this->input->rules = [
   'age'      => 'fixed(20)',
   'tags'     => 'fixed(3)',
   'username' => 'fixed(5)'
];

between

Ensures a value lies between two limits. Works for numeric, string (length), and array elements.

RuleParameterDescription
between(min,max)(float\|int, float\|int)Value must be ≥ min and ≤ max.
$this->input->rules = [
   'age'       => 'between(18, 60)',  // numeric
   'tags'      => 'between(2, 10)',  // array elements
   'username'  => 'between(3, 20)',   // string length
];

alphanumeric

Allows only letters and numbers.

RuleParameterDescription
alphanumericvoidOnly letters (a–z, A–Z) and numbers (0–9).
$this->input->rules = [
   'user_id' => 'alphanumeric'
];

alphabet

Allows only letters.

RuleParameterDescription
alphabetvoidOnly letters (a–z, A–Z).
$this->input->rules = [
   'first_name' => 'alphabet'
];

numeric

Checks that the value is numeric.

RuleParameterDescription
numericvoidMust be numeric (integer or float).
$this->input->rules = [
   'age' => 'numeric'
];

integer

Ensures the value is an integer.You can optionally specify whether it must be positive or negative.

RuleParameterDescription
integer(sign)?string: noneMust be integer. Optionally specify positive or negative.
$this->input->rules = [
   'quantity' => 'integer(positive)'
];

float

Ensures the value is a floating-point number.You can optionally specify positive or negative.

RuleParameterDescription
float(sign)?string: noneMust be float. Optionally specify positive or negative.
$this->input->rules = [
   'rating' => 'float(positive)'
];

decimal

Checks that the value is a floating-point number containing a decimal point.Integers or scientific notation (e.g., 1e3) are not considered valid decimals.

Optionally specify positive or negative.

RuleParameterDescription
decimal(sign)?string: noneMust be a valid decimal number (e.g., 12.5).
$this->input->rules = [
   'price' => 'decimal(positive)'
];

boolean

Validates typical boolean values such as 'true', 'false', 1, or 0.

RuleParameterDescription
booleanvoidMust be a boolean-like value (true, false, 1, or 0).
$this->input->rules = [
   'is_active' => 'boolean'
];

binary

Validates whether the value represents a binary sequence or a PHP-style binary literal.By default, this rule accepts numbers containing only 0 and 1, or strings like 0b1010.It does not allow non-text or raw binary data unless you explicitly enable printable fallback.

RuleParameterDescription
binary(strict, allowPrintable)(?bool: false, ?bool: false)Validates binary digits or PHP-style binary literals (e.g., 1010, 0b1010). If $allowPrintable is true, printable ASCII text is also accepted.
$this->input->rules = [
   // Accepts "1010", "0b1010"
   'binary_code' => 'binary',

   // Strict mode: only "0" and "1" sequences allowed
   'pure_bits' => 'binary(true)',

   // Non-strict with printable ASCII fallback
   'file_content' => 'binary(false,true)'
];

hexadecimal

Checks that the value is a valid hexadecimal string (0–9, A–F, a–f).It must be a string and cannot contain non-hex characters.

RuleParameterDescription
hexadecimalvoidMust be a valid hexadecimal string (e.g., a3f9b0).
$this->input->rules = [
   'hash' => 'hexadecimal',
   'color_code' => 'hexadecimal'
];

string

Ensures the value is a string.

RuleParameterDescription
stringvoidMust be string.
$this->input->rules = [
   'title' => 'string'
];

array

Ensures the value is an array.

RuleParameterDescription
arrayvoidMust be array.
$this->input->rules = [
   'items' => 'array'
];

json

Validates that the value is valid JSON.

RuleParameterDescription
jsonvoidMust be valid JSON.
$this->input->rules = [
   'config' => 'json'
];

url

Validates that the value is a properly formatted URL.

RuleParameterDescription
urlvoidMust be valid URL.
$this->input->rules = [
   'website' => 'url'
];

scheme

Ensures the URL matches the specified scheme (e.g., http, https).

RuleParameterDescription
scheme(value)stringMust match given URL scheme.
$this->input->rules = [
   'site' => 'scheme(https)'
];

ip

Validates that the value is a valid IP address.You can specify the version: 4, 6, or 0 for any.

RuleParameterDescription
ip(version)?int:0Must be valid IPv4, IPv6, or both.
$this->input->rules = [
   'client_ip' => 'ip(4)'
];

email

Validates that the value is a properly formatted email address.

RuleParameterDescription
emailvoidMust be valid email address.
$this->input->rules = [
   'email' => 'email'
];

latitude

Alias: lat

Ensures a field value is a valid latitude.Latitude must be between -90 and 90.

  • When strict is true, it also checks numeric format and decimal precision based on the precision parameter.
RuleParameterDescription
latitude(isStrict, precision)(?bool:false, ?int:6)Must be a valid latitude. Strict mode enforces numeric format and precision.
$this->input->rules = [
   'latitude' => 'lat(true, 6)'
];

longitude

Alias: lng

Ensures a field value is a valid longitude.Longitude must be between -180 and 180.

  • When strict is true, it also checks numeric format and decimal precision based on the precision parameter.
RuleParameterDescription
longitude(isStrict, precision)(?bool:false, ?int:6)Must be a valid longitude. Strict mode enforces numeric format and precision.
$this->input->rules = [
   'longitude' => 'longitude(true, 6)'
];

latlng

Ensures a field value is a valid latitude,longitude string.Format: latitude,longitude (e.g., 12.971603,77.594605).

  • Both latitude and longitude are validated according to their respective ranges.
  • When strict is true, decimal precision is enforced for both values.
RuleParameterDescription
latlng(isStrict, precision)(?bool:false, ?int:6)Must be a valid latitude and longitude string. Strict mode enforces numeric format and precision.
$this->input->rules = [
   'coordinates' => 'latlng(true, 6)'
];

username

Ensure that field value is a valid usernames format.Optionally allow uppercase letters and define a list of reserved names to reject.

RuleParameterDescription
username(allowUppercase, reservedList)(?bool:true, ?array:[])Must be valid username; can restrict uppercase and reserved names.
$this->input->rules = [
   'username' => 'username(false, [admin,root])'
];

The rule is useful for validating usernames during account creation, ensuring that new users don’t choose reserved or restricted names.


phone

Ensure that field value is a valid phone number.Supports minimum and maximum length.

RuleParameterDescription
phone(minLength, maxLength)(?int:10, ?int:15)Must be valid phone number.
$this->input->rules = [
   'phone' => 'phone(10, 15)'
];

uuid

Ensures that a field value is a valid UUID of the specified version.Supported versions: 1–5.

RuleParameterDescription
uuid(version)intMust be a valid UUID of the given version.
$this->input->rules = [
   'identifier' => 'uuid(4)'
];

match

Checks if a field value matches a given regular expression.

RuleParameterDescription
match(pattern)regexValue must match the regex pattern.
$this->input->rules = [
   'slug' => 'match(^[a-z0-9_-]+$)'
];

equals

Checks if the field value matches another field’s value.

RuleParameterDescription
equals(field)stringValue must equal the value of another field.
$this->input->rules = [
   'confirm_password' => 'equals(password)'
];

not_equal

Ensures the value does not equal another field’s value.

RuleParameterDescription
not_equal(field)stringMust not equal the value of another field.
$this->input->rules = [
   'new_password' => 'not_equal(old_password)'
];

in_array

Validates that a field value exists within a specified list of values.If strict is true, the type of the field value is also checked (default is true).

RuleParameterDescription
in_array(values, strict)(array, bool: true)Field value must match one of the listed values.
$this->input->rules = [
   'role' => 'in_array([admin,user,guest])'
];

is_value

Ensures the field value matches exactly the given value.

RuleParameterDescription
is_value(value)mixedMust equal the specified value.
$this->input->rules = [
   'status' => 'is_value(active)'
];

is_list

Validates a comma-separated list (like apple,banana,mango) and optionally ensures a minimum number of items.

RuleParameterDescription
is_list(min)?int: 1Must be a valid comma-separated list with at least min items. Defaults to 1, allowing a single value.
$this->input->rules = [
   'tags' => 'is_list',       // At least 1 item required (default)
   'indexes' => 'is_list(3)', // At least 3 items required
];

Examples:

// Valid inputs
'tags' => 'apple'          // true (1 item)
'tags' => 'apple,banana'   // true (2 items)
'indexes' => '1,2,3'       // true (3 items)

// Invalid inputs
'tags' => ''             // false (empty string)
'indexes' => '1,2'       // false (less than min 3)
'tags' => 'foo,,bar'     // false (empty item between commas)

keys_exists

Validates that an array field contains the specified keys.When strict is true, the array must not contain any additional keys beyond those specified.

RuleParameterDescription
keys_exists(keys, strict)(array, bool: false)Ensures the array has all specified keys. If $strict is true, no extra keys are allowed.
$this->input->rules = [
   // Must contain all specified keys, extra keys allowed
   'user_data' => 'keys_exists([name,email,age])',       

   // Must contain only the specified keys, no extra keys
   'user_data' => 'keys_exists([name,email,age], true)'  
];

key_exists

Validates that an array field contains at least one of the specified keys.

RuleParameterDescription
key_exists(keys)arrayEnsures the array contains at least one of the specified keys.
$this->input->rules = [
   'options' => 'key_exists([name,email,age])'  
];

path

Validates that the value is a valid file or directory path.Optionally check if it’s readable or writable.

RuleParameterDescription
path(access)stringMust be valid path; check readability/writability if specified.
$this->input->rules = [
   'file_path' => 'path(readable)'
];

callback

Executes a custom validation function on the field value.

The callback receives the field value and optionally the field name:

  • fn(mixed $value, string $field): bool (default, 2 arguments)
  • fn(mixed $value): bool (if maxArgs is set to 1)

The function must return true or false to indicate whether the value passes validation.

RuleParameterDescription
callback(fn, maxArgs)(callable, int: 2)Calls a user-defined function to validate the field.
$this->input->rules = [
   'amount' => 'callback(checkAmount)',      // 2 arguments by default
   'list'   => 'callback(is_array, 1)'      // Only value argument, avoid field name
];

Supported Callable Formats:

'callable(myFunction)'                        // Plain function
'callable([\Foo\Namespace\MyClass, method])' // Static class method
'callable(\Foo\Namespace\MyClass@method)'    // Instance method (auto-instantiated)
'callable(\Foo\Namespace\MyClass::method)'   // Static method

Signature Notes:

  • callable(myFunction, 2):

    function myFunction(mixed $value, string $field): bool
    { 
      // ...
    }
  • callable(myFunction, 1):

    function myFunction(mixed $value): bool
    {
      // ...
    }

Note:

  • Instance methods (Class@method) are automatically instantiated.
  • Static methods (Class::method or [Class::class, method]) are called directly.
  • Only string function names, static arrays, and class method strings are supported. Objects are not supported.

default

Uses a fallback default value if the field is empty or not included in request data.

Alias: fallback().

RuleParameterDescription
fallback(value)mixedDefault value if empty (defaults to null).
$this->input->rules = [
   'country' => 'default(Unknown)'
];

Note:Default cannot be used with other strict rule validation (e.g, required, in_array etc...).