MValidate

Loaded from
core/util/MValidate

All MValidate functions return boolean values. The value being passed in either passes and is valid, aka TRUE, or fails and is invalid, or FALSE.

Public Methods



email($email:String):Boolean


The email function uses regular expressions to check the validity of an e-mail address.

MValidate::email("alanjames1987@gmail.com"); 
bool(true)
MValidate::email("alanjames1987@com"); 
bool(false)

optional($input:String):Boolean


Validates that a variable is declared, exists in memory, and has some value.
"", " ", array(), 0, FALSE will return TRUE as they are declared variables.
An undeclared variable or NULL will return FALSE.

In the example below we first must declare a variable in order to pass it into the function as this function only accepts passing by reference.
$value = "some value"; 
MValidate::optional($value);
bool(true)
$value = ""; 
MValidate::optional($value);
bool(true)
$value = " "; 
MValidate::optional($value);
bool(true)
$value = array(); 
MValidate::optional($value);
bool(true)
$value = 0; 
MValidate::optional($value);
bool(true)
$value = FALSE; 
MValidate::optional($value);
bool(true)
Unset $value.
unset($value); 
MValidate::optional($value);
bool(false)
$value = NULL; 
MValidate::optional($value);
bool(false)

required($input:String):Boolean


Validates that a variable is decalred and has a non empty value.
0, FALSE will return TRUE.
"", " ", array(), an undeclared variable, and NULL will return FALSE.

In the example below we first must declare a variable in order to pass it into the function as this function accepts passing by reference.
$value = "some value"; 
MValidate::required($value);
bool(true)
$value = ""; 
MValidate::required($value);
bool(false)
$value = " "; 
MValidate::required($value);
bool(false)
$value = array(); 
MValidate::required($value);
bool(false)
$value = 0; 
MValidate::required($value);
bool(true)
$value = FALSE; 
MValidate::required($value);
bool(true)
Unset $value.
unset($value); 
MValidate::required($value);
bool(false)
$value = NULL; 
MValidate::required($value);
bool(false)

only_contain($input:Mixed, choices:Array):Boolean


Validates that a variable contains only the values is in the array.
The input can not have any values other than what is in the array.
If the input is a String each letter is checked against the choice array.
If the input is an Array each item in the array is checked against the choice array.

MValidate::only_contain("red", array("r", "e", "a", "d", "y")); 
bool(true)
MValidate::only_contain("Red", array("r", "e", "a", "d", "y")); 
bool(false)
MValidate::only_contain(array("comedy", "horror"), array("action", "comedy", "drama", "horror")); 
bool(true)
MValidate::only_contain(array("romcom", "animated"), array("action", "comedy", "drama", "horror")); 
bool(false)

must_contain($input:Mixed, choices:Array):Boolean


Validates that a variable contains every value in the array.
The input can have other values but must have what is in the array.
If the input is a String each letter is checked against the choice array.
If the input is an Array each item in the array is checked against the choice array.

MValidate::must_contain(array("red", "orange", "yellow"), array("red", "yellow")); 
bool(true)
MValidate::must_contain(array("red", "orange", "yellow"), array("red", "yellow", "blue")); 
bool(false)

cant_contain($input:Mixed, choices:Array):Boolean


Validates that a variable does not contain what is in the array.
The input can have other values but must not have what is in the array.
If the input is a String each letter is checked against the array.
If the input is an Array each item in the array is checked against the choice array.

MValidate::cant_contain(array("red", "orange", "yellow"), array("green", "blue", "violet")); 
bool(true)
MValidate::cant_contain(array("red", "orange", "yellow"), array("yellow", "green")); 
bool(false)

included_in($input:Mixed, choices:Array):Boolean


Validates that a variable is in a list of choices.
The comparison is case sensitive, so "red" and "Red" are not the same.

MValidate::included_in("Red", array("Red", "Yellow", "Blue")); 
bool(true)
MValidate::included_in("red", array("Red", "Yellow", "Blue")); 
bool(false)

excluded_from($input:Mixed, choices:Array):Boolean


Validates that a variable is not in a list of choices.
The comparison is case sensitive, so "red" and "Red" are not the same.

MValidate::excluded_from("Red", array("Red", "Yellow", "Blue")); 
bool(false)
MValidate::excluded_from("red", array("Red", "Yellow", "Blue")); 
bool(true)

between($input:Number, $min:Number, $max:Number):Boolean


Validates that a variable is between two numbers.

MValidate::between(5, 0, 10); 
bool(true)

multiple_of($input:Number, $multiple:Number):Boolean


Validates that an input is a multiple of a number.

MValidate::multiple_of(5, 10); 
bool(false)
MValidate::multiple_of(10, 5); 
bool(true)

even($input:Number):Boolean


Validates that an input is an even number.

MValidate::even(5); 
bool(false)
MValidate::even(4); 
bool(true)

odd($input:Number):Boolean


Validates that an input is an odd number.

MValidate::odd(5); 
bool(true)
MValidate::odd(4); 
bool(false)

state($state:String):Boolean


Validates that a state or abbriation for a state is a valid state.
Washington DC is considered a state to this function.
This function is case insensitive.

MValidate::state("FL"); 
bool(true)
MValidate::state("dc"); 
bool(true)
MValidate::state("guam"); 
bool(false)