Trongate PHP Framework Docs
Introduction
Basic Concepts
Understanding Routing
Intercepting Requests
Module Fundamentals
Database Operations
Templates
Helpers
Form Handling
Form Validation
Working With Files
Image Manipulation
Working With Dates & Times
Language Control
Authorization & Authentication
Tips And Best Practices

Validation Rules Reference

This page provides a complete reference of all built-in validation rules available in Trongate v2. Each rule validates a specific aspect of form data, and most rules are optional — fields only validate when they contain data (except required).

Optional Fields: All validation rules except required skip validation if the field is empty. To validate an empty field, use the required rule first.

Quick Reference Table

Rule Parameter Purpose
requiredField cannot be empty
numericMust be a number
integerMust be a whole number
decimalMust be a decimal number
valid_emailMust be valid email address
valid_urlMust be valid URL
valid_ipMust be valid IP address
valid_dateMust be valid date (YYYY-MM-DD)
valid_timeMust be valid time (HH:MM or HH:MM:SS)
valid_datetime_localMust be valid datetime (YYYY-MM-DDTHH:MM)
valid_monthMust be valid month (YYYY-MM)
valid_weekMust be valid week (YYYY-W##)
min_lengthnumberMinimum character length
max_lengthnumberMaximum character length
exact_lengthnumberExact character length
greater_thannumberMust be greater than value
less_thannumberMust be less than value
matchesfieldMust match another field
allowed_typesextensionsAllowed file types
max_sizekilobytesMaximum file size
min_sizekilobytesMinimum file size
is_imageMust be valid image
max_widthpixelsMaximum image width
min_widthpixelsMinimum image width
max_heightpixelsMaximum image height
min_heightpixelsMinimum image height
exact_widthpixelsExact image width
exact_heightpixelsExact image height
squareImage must be square

Standard Rules

required

The field cannot be empty. This is the only rule that validates empty fields — all other rules skip validation if the field is empty.

Syntax:

Error Message:

numeric

The field must contain a numeric value (integer or decimal, positive or negative).

Syntax:

Valid Values: 42, -15, 3.14, -2.5

Invalid Values: abc, 12x, 1,000

Error Message:

integer

The field must contain a whole number (no decimal places, positive or negative).

Syntax:

Valid Values: 42, -15, 0

Invalid Values: 3.14, abc, 42.0

Error Message:

decimal

The field must contain a decimal number (with or without decimal places).

Syntax:

Valid Values: 19.99, 10, -3.5

Invalid Values: $19.99, abc

Error Message:

Format Rules

valid_email

The field must contain a valid email address.

Syntax:

Valid Values: [email protected], [email protected]

Invalid Values: user@, @example.com, user [email protected]

Error Message:

valid_url

The field must contain a valid URL (with protocol).

Syntax:

Valid Values: https://example.com, http://example.com/path

Invalid Values: example.com, not a url

Error Message:

valid_ip

The field must contain a valid IP address (IPv4 or IPv6).

Syntax:

Valid Values: 192.168.1.1, 2001:0db8:85a3::8a2e:0370:7334

Invalid Values: 256.256.256.256, not an ip

Error Message:

Date and Time Rules

valid_date

The field must be a valid date in YYYY-MM-DD format.

Syntax:

Valid Values: 2024-03-18, 1999-12-25

Invalid Values: 03/18/2024, 2024-13-01, 2024-02-30

Error Message:

valid_time

The field must be a valid time in HH:MM or HH:MM:SS format (24-hour).

Syntax:

Valid Values: 14:30, 09:15:45, 23:59:59

Invalid Values: 2:30 PM, 25:00, 14:60:00

Error Message:

valid_datetime_local

The field must be a valid datetime in YYYY-MM-DDTHH:MM format (ISO 8601 local datetime).

Syntax:

Valid Values: 2024-03-18T14:30, 2024-12-25T23:59

Invalid Values: 2024-03-18 14:30, 03/18/2024T14:30

Error Message:

valid_month

The field must be a valid month in YYYY-MM format.

Syntax:

Valid Values: 2024-03, 2024-12

Invalid Values: 2024-13, 03-2024, March 2024

Error Message:

valid_week

The field must be a valid week in YYYY-W## format (ISO 8601 week date).

Syntax:

Valid Values: 2024-W12, 2024-W52

Invalid Values: 2024-W53 (if year doesn't have 53 weeks), W12-2024

Error Message:

Length Rules

min_length

The field must be at least the specified number of characters long.

Syntax:

Valid for min_length[3]: abc, john, user123

Invalid for min_length[3]: ab, x

Error Message:

max_length

The field cannot exceed the specified number of characters.

Syntax:

Valid for max_length[50]: New York, Los Angeles

Invalid for max_length[50]: Any string longer than 50 characters

Error Message:

exact_length

The field must be exactly the specified number of characters long.

Syntax:

Valid for exact_length[5]: 12345, abcde

Invalid for exact_length[5]: 1234, 123456

Error Message:

Comparison Rules

greater_than

The field must contain a value greater than the specified number.

Syntax:

Valid for greater_than[18]: 19, 25, 100

Invalid for greater_than[18]: 18, 17, 0

Error Message:

less_than

The field must contain a value less than the specified number.

Syntax:

Valid for less_than[100]: 99, 50, 0

Invalid for less_than[100]: 100, 101

Error Message:

matches

The field must match the value of another field. Commonly used for password confirmation.

Syntax:

Valid: Both fields contain the same value

Invalid: Fields contain different values

Error Message:

Note: The parameter is the name of the field to compare against, not a label.

File Validation Rules

allowed_types

The uploaded file must be one of the specified file types (by extension).

Syntax:

Parameters: Comma-separated list of allowed file extensions (without dots)

Valid for allowed_types[pdf,doc,docx]: resume.pdf, letter.doc, report.docx

Invalid for allowed_types[pdf,doc,docx]: image.jpg, video.mp4

Error Message:

max_size

The uploaded file size cannot exceed the specified limit in kilobytes.

Syntax:

Parameters: Maximum file size in kilobytes

Error Message:

min_size

The uploaded file size must be at least the specified limit in kilobytes.

Syntax:

Parameters: Minimum file size in kilobytes

Error Message:

Image Validation Rules

is_image

The uploaded file must be a valid image file (JPG, PNG, GIF, or WEBP).

Syntax:

Valid File Types: JPG, PNG, GIF, WEBP

Error Message:

max_width

The image width cannot exceed the specified number of pixels.

Syntax:

Parameters: Maximum width in pixels

Error Message:

min_width

The image width must be at least the specified number of pixels.

Syntax:

Parameters: Minimum width in pixels

Error Message:

max_height

The image height cannot exceed the specified number of pixels.

Syntax:

Parameters: Maximum height in pixels

Error Message:

min_height

The image height must be at least the specified number of pixels.

Syntax:

Parameters: Minimum height in pixels

Error Message:

exact_width

The image width must be exactly the specified number of pixels.

Syntax:

Parameters: Exact width in pixels

Error Message:

exact_height

The image height must be exactly the specified number of pixels.

Syntax:

Parameters: Exact height in pixels

Error Message:

square

The image must be square (equal width and height).

Syntax:

Valid: Image with width = height (e.g., 200x200, 500x500)

Invalid: Any rectangular image (e.g., 400x300, 1920x1080)

Error Message:

Combining Rules

Multiple rules can be combined using the pipe character (|):

Early Exit: Validation stops at the first error for each field. If required fails, other rules for that field are not checked.

Complete Example