Documentation
SPHPlayground manual
sphplayground
sphplayground

DATA VALIDATION: Introduction

User input validation is a critical part of any responsive HTML application. This Framework contains its own user input validation mechanism which includes both server- and clientside components. This section is about the serverside validation mechanism. The cornerstone of it is the Validator interface. This interface defines the minimum properties required for any SPHP framework based validator.

The MessageManager message container

The MessageManager handles error messages in all validators

The NotEmpty class

The NotEmpty validates only that the given input has a non empty value.

All of the following values are considered as empty:

  1. (a variable declared, but without a value)
  2. NULL values
  3. empty arrays
  4. "" an empty string
  5. strings containing only following characters
    • " " (ASCII 32 (0x20)), an ordinary space
    • "\t" (ASCII 9 (0x09)), a tab
    • "\n" (ASCII 10 (0x0A)), a new line (line feed)
    • "\r" (ASCII 13 (0x0D)), a carriage return
    • "\0" (ASCII 0 (0x00)), the NUL-byte
    • "\x0B" (ASCII 11 (0x0B)), a vertical tab

The Regex class

The Regex validates the input against the given regular expression. The input is valid if it matches the given pattern.

The StringLength class

The StringLength simply validates the input length. This validator supports three types of validation

  1. Lower bound validation: the length of the input must be above a given limit.
  2. Upper bound validation: the length of the input must be below a given limit.
  3. Range validation: the length of the input must be between the lower and upper limits.

The ValidatorChain class

The ValidatorChain is an aggregation of Validator objects. It validates the given input against all of its inner validators and the input is valid only if it passes all of them.

The MapValidator validator

A MapValidator is an aggregate of validators validating user inputs data provided by HTML forms like the ones implementing HtmlForm. A MapValidator can validate PHP's native arrays and just about any kind of Traversable data containing key value pairs.

MapValidator supports two ways of manipulating validators for named input data values.

  1. By using PHP's array notation provided by the ArrayAccess interface
    • IMPORTANT! the offset key points to the corresponding offset in the data that is to be validated
  2. By using chainable object oriented methods