SproutCMS

This is the code documentation for the SproutCMS project

Page options:

Inherited members

class Validity

New validation class for Sprout 3.
All of its methods should give useful errors by throwing a ValidationException.
Used with the Validator class.

Functions

NameVisibilityDescription
allInArraypublic (static)Checks each value of an array is one of the allowed values
allInSetpublic (static)Checks all selected values belong to a database SET definition
allInTablepublic (static)Checks all selected values match IDs in a corresponding table
allMatchpublic (static)All field values must match (e.g. password1 and password2 must match)
allUniquepublic (static)All field values must be unique (e.g. home phone and work phone cannot be the same)
binarypublic (static)Checks that a value is binary; either a '1' or a '0'.
dateMySQLpublic (static)Checks if a value is a date in MySQL format (YYYY-MM-DD)
dateRangepublic (static)Checks that a date range is valid.
datetimeMySQLpublic (static)Checks if a value is a datetime in MySQL format (YYYY-MM-DD HH:MM:SS)
emailpublic (static)Validate email, commonly used characters only
inArraypublic (static)Checks a value is one of the allowed values
inEnumpublic (static)Validates a value meant for an ENUM field
inTablepublic (static)Checks a value matches an ID in a corresponding table
ipv4Addrpublic (static)Checks that a value is a valid IPv4 address
ipv4AddrOrCidrpublic (static)Checks that a value is a valid IPv4 address or CIDR block
ipv4Cidrpublic (static)Checks that a value is a valid IPv4 CIDR block
lengthpublic (static)Checks the length of a string is within an allowed range
numericpublic (static)Checks that a value is numeric (integral or decimal)
oneRequiredpublic (static)At least one value must be specified (e.g. one of email/phone/mobile)
passwordpublic (static)Validate password by length, type of characters, and list of common passwords
phonepublic (static)Checks if a phone number is valid.
positiveIntpublic (static)Checks if a value is a positive integer
proseTextpublic (static)Checks whether a string is made up of the kinds of characters that make up prose
rangepublic (static)Checks that a value is numeric (integral or decimal) and within a given inclusive range
regexpublic (static)Checks that a value matches a regular expression
timeMySQLpublic (static)Checks if a value is a time in MySQL format (HH:MM:SS)
uniqueValuepublic (static)Checks that a unique value doesn't already exist in the database, e.g. a username or email address.

public allInArray

void Validity::allInArray ( array $val , array $allowed );

Checks each value of an array is one of the allowed values

public allInSet

void Validity::allInSet ( array $val , string $table , string $col );

Checks all selected values belong to a database SET definition

public allInTable

void Validity::allInTable ( array $val , string $table );

Checks all selected values match IDs in a corresponding table

public allMatch

void Validity::allMatch ( array $vals );

All field values must match (e.g. password1 and password2 must match)

public allUnique

void Validity::allUnique ( array $vals );

All field values must be unique (e.g. home phone and work phone cannot be the same)

public binary

void Validity::binary ( string $val );

Checks that a value is binary; either a '1' or a '0'.

public dateMySQL

void Validity::dateMySQL ( string $val );

Checks if a value is a date in MySQL format (YYYY-MM-DD)

public dateRange

void Validity::dateRange ( array $vals [, string $min [, string $max [, bool $enforce_ordering ]]] );

Checks that a date range is valid.

public datetimeMySQL

void Validity::datetimeMySQL ( string $val );

Checks if a value is a datetime in MySQL format (YYYY-MM-DD HH:MM:SS)

public email

void Validity::email ( string $val );

Validate email, commonly used characters only

public inArray

void Validity::inArray ( string $val , array $allowed );

Checks a value is one of the allowed values

public inEnum

bool Validity::inEnum ( string $val , string $table , string $col );

Validates a value meant for an ENUM field

public inTable

void Validity::inTable ( string $val , string $table );

Checks a value matches an ID in a corresponding table

public ipv4Addr

void Validity::ipv4Addr ( string $val );

Checks that a value is a valid IPv4 address

public ipv4AddrOrCidr

void Validity::ipv4AddrOrCidr ( string $val );

Checks that a value is a valid IPv4 address or CIDR block

public ipv4Cidr

void Validity::ipv4Cidr ( string $val );

Checks that a value is a valid IPv4 CIDR block

public length

void Validity::length ( string $val , int $min , int $max );

Checks the length of a string is within an allowed range

public numeric

void Validity::numeric ( string $val );

Checks that a value is numeric (integral or decimal)

public oneRequired

void Validity::oneRequired ( array $vals );

At least one value must be specified (e.g. one of email/phone/mobile)

public password

void Validity::password ( string $val );

Validate password by length, type of characters, and list of common passwords

public phone

void Validity::phone ( string $val [, int $min_digits ] );

Checks if a phone number is valid.

public positiveInt

void Validity::positiveInt ( string $val );

Checks if a value is a positive integer

public proseText

void Validity::proseText ( string $str );

Checks whether a string is made up of the kinds of characters that make up prose

Allowed: letters, numbers, space, punctuation
Allowed punctuation:
   ' " / ! ? @ # $ % & ( ) - : ; . ,

public range

void Validity::range ( string $val , number $min , number $max );

Checks that a value is numeric (integral or decimal) and within a given inclusive range

public regex

void Validity::regex ( string $val , string $pattern );

Checks that a value matches a regular expression

public timeMySQL

void Validity::timeMySQL ( string $val );

Checks if a value is a time in MySQL format (HH:MM:SS)

public uniqueValue

void Validity::uniqueValue ( string $val , string $table , string $column [, int $id [, string $error_msg ]] );

Checks that a unique value doesn't already exist in the database, e.g. a username or email address.
This is to give a friendlier frontend to DB errors pertaining to UNIQUE constraints.
N.B. this function uses LIKE for case-insensitive matching, so it's even stricter than a UNIQUE constraint.