class Strings (View source)

Functions useful for validating strings.

Methods

bool
email(string $em, bool $testMXRecord = false, bool $strict = false)

Returns true if the provided email is valid.

bool
alphanum(string $value, bool $allowSpaces = false, bool $allowDashes = false)

Returns true on whether the passed string is completely alpha-numeric, if the value is not a string or is an empty string false will be returned.

bool
handle(string $handle)

Returns true if the passed string is a valid "handle" (e.g. only letters, numbers, or a _ symbol).

bool
notempty(string $field)

Returns false if the string is empty (including trim()).

bool
min(string $str, int $length)

Returns true on whether the passed string is larger or equal to the passed length.

bool
max(string $str, int $length)

Returns true on whether the passed is smaller or equal to the passed length.

int
containsNumber(string $str)

Returns 0 if there are no numbers in the string, or returns the number of numbers in the string.

int
containsUpperCase(string $str)

Returns 0 if there are no upper case letters in the string, or returns the number of upper case letters in the string.

int
containsLowerCase(string $str)

Returns 0 if there are no lower case letters in the string, or returns the number of lower case letters in the string.

int
containsSymbol(string $str)

Returns 0 if there are no symbols in the string, or returns the number of symbols in the string.

Details

bool email(string $em, bool $testMXRecord = false, bool $strict = false)

Returns true if the provided email is valid.

Parameters

string $em

The email address to be tested

bool $testMXRecord

Set to true if you want to perform dns record validation for the domain, defaults to false

bool $strict

Strict email validation

Return Value

bool

bool alphanum(string $value, bool $allowSpaces = false, bool $allowDashes = false)

Returns true on whether the passed string is completely alpha-numeric, if the value is not a string or is an empty string false will be returned.

Parameters

string $value
bool $allowSpaces

whether or not spaces are permitted in the field contents

bool $allowDashes

whether or not dashes (-) are permitted in the field contents

Return Value

bool

bool handle(string $handle)

Returns true if the passed string is a valid "handle" (e.g. only letters, numbers, or a _ symbol).

Parameters

string $handle

Return Value

bool

bool notempty(string $field)

Returns false if the string is empty (including trim()).

Parameters

string $field

Return Value

bool

bool min(string $str, int $length)

Returns true on whether the passed string is larger or equal to the passed length.

Parameters

string $str
int $length

Return Value

bool

bool max(string $str, int $length)

Returns true on whether the passed is smaller or equal to the passed length.

Parameters

string $str
int $length

Return Value

bool

int containsNumber(string $str)

Returns 0 if there are no numbers in the string, or returns the number of numbers in the string.

Parameters

string $str

Return Value

int

int containsUpperCase(string $str)

Returns 0 if there are no upper case letters in the string, or returns the number of upper case letters in the string.

Parameters

string $str

Return Value

int

int containsLowerCase(string $str)

Returns 0 if there are no lower case letters in the string, or returns the number of lower case letters in the string.

Parameters

string $str

Return Value

int

int containsSymbol(string $str)

Returns 0 if there are no symbols in the string, or returns the number of symbols in the string.

Parameters

string $str

Return Value

int