reference appendices

Available Filters

The Filter extension provides validation and sanitisation filters. Validation asks whether input satisfies a format; sanitisation transforms input and must not be mistaken for domain validation or output escaping.

Use This Reference When

  • Validating email addresses and integers at input boundaries.
  • Inspecting available filters with filter_list().
  • Separating input checks from HTML escaping and business rules.

Validate an Integer

PHP example
<?php

$value = filter_var('12', FILTER_VALIDATE_INT, [
    'options' => ['min_range' => 1],
]);
var_dump($value);

// Prints:
// int(12)

Do not use sanitisation as a security blanket. Validate expected input, model the domain rule, and escape output for its destination.

Practice

Validate a Port Number

Use filter_var() to validate an integer port between 1 and 65535. Test a valid and invalid value.

Show solution

Use FILTER_VALIDATE_INT with min_range and max_range options. Compare the result strictly against false because zero can be a valid integer in other domains.