Validation Class Reference

Inheritance diagram for Validation:

Object List of all members.

Public Member Functions

 __reset ()
 _check ()
 _extract ($params)
 _luhn ()
 alphaNumeric ($check)
 between ($check, $min, $max)
 blank ($check)
 boolean ($check)
 cc ($check, $type= 'fast', $deep=false, $regex=null)
 comparison ($check1, $operator=null, $check2=null)
 custom ($check, $regex=null)
 date ($check, $format= 'ymd', $regex=null)
 decimal ($check, $places=null, $regex=null)
 email ($check, $deep=false, $regex=null)
 equalTo ($check, $comparedTo)
 extension ($check, $extensions=array('gif', 'jpeg', 'png', 'jpg'))
 file ($check)
 inList ($check, $list)
 ip ($check)
 maxLength ($check, $max)
 minLength ($check, $min)
 money ($check, $symbolPosition= 'left')
 multiple ($check, $options=array())
 notEmpty ($check)
 numeric ($check)
 phone ($check, $regex=null, $country= 'all')
 postal ($check, $regex=null, $country=null)
 range ($check, $lower=null, $upper=null)
 ssn ($check, $regex=null, $country=null)
 time ($check)
 url ($check, $strict=false)
 userDefined ($check, $object, $method, $args=null)

Static Public Member Functions

getInstance ()

Public Attributes

 $__pattern
 $check = null
 $country = null
 $deep = null
 $errors = array()
 $regex = null
 $type = null

Detailed Description

Definition at line 55 of file validation.php.


Member Function Documentation

Validation::__reset (  ) 

Reset internal variables for another validation run.

Returns:
void private

Definition at line 919 of file validation.php.

Validation::_check (  ) 

Runs a regular expression match.

Returns:
boolean Success of match protected

Definition at line 846 of file validation.php.

Referenced by cc(), and date().

Validation::_extract ( params  ) 

Get the values to use when value sent to validation method is an array.

Parameters:
array $params Parameters sent to validation method
Returns:
void protected

Definition at line 864 of file validation.php.

Validation::_luhn (  ) 

Luhn algorithm

See also:
http://en.wikipedia.org/wiki/Luhn_algorithm
Returns:
boolean Success protected

Definition at line 891 of file validation.php.

Validation::alphaNumeric ( check  ) 

Checks that a string contains only integer or letters

Returns true if string contains only integer or letters

$check can be passed as an array: array('check' => 'valueToCheck');

Parameters:
mixed $check Value to check
Returns:
boolean Success public

Definition at line 165 of file validation.php.

References $check, check(), and getInstance().

Validation::between ( check,
min,
max 
)

Checks that a string length is within s specified range. Spaces are included in the character count. Returns true is string matches value min, max, or between min and max,

Parameters:
string $check Value to check for length
integer $min Minimum value in range (inclusive)
integer $max Maximum value in range (inclusive)
Returns:
boolean Success public

Definition at line 191 of file validation.php.

References $check.

Validation::blank ( check  ) 

Returns true if field is left blank -OR- only whitespace characters are present in it's value Whitespace characters include Space, Tab, Carriage Return, Newline

$check can be passed as an array: array('check' => 'valueToCheck');

Parameters:
mixed $check Value to check
Returns:
boolean Success public

Definition at line 206 of file validation.php.

References $check, and getInstance().

Validation::boolean ( check  ) 

Boolean validation, determines if value passed is a boolean integer or true/false.

Parameters:
string $check a valid boolean
Returns:
boolean Success public

Definition at line 449 of file validation.php.

References $check.

Validation::cc ( check,
type = 'fast',
deep = false,
regex = null 
)

Validation of credit card numbers. Returns true if $check is in the proper credit card format.

Parameters:
mixed $check credit card number to validate
mixed $type 'all' may be passed as a sting, defaults to fast which checks format of most major credit cards if an array is used only the values of the array are checked. Example: array('amex', 'bankcard', 'maestro')
boolean $deep set to true this will check the Luhn algorithm of the credit card.
string $regex A custom regex can also be passed, this will be used instead of the defined regex values
Returns:
boolean Success public
See also:
Validation::_luhn()

Definition at line 232 of file validation.php.

References $check, $regex, _check(), check(), and getInstance().

Validation::comparison ( check1,
operator = null,
check2 = null 
)

Used to compare 2 numeric values.

Parameters:
mixed $check1 if string is passed for a string must also be passed for $check2 used as an array it must be passed as array('check1' => value, 'operator' => 'value', 'check2' -> value)
string $operator Can be either a word or operand is greater >, is less <, greater or equal >= less or equal <=, is less <, equal to ==, not equal !=
integer $check2 only needed if $check1 is a string
Returns:
boolean Success public

Definition at line 305 of file validation.php.

References __(), and getInstance().

Validation::custom ( check,
regex = null 
)

Used when a custom regular expression is needed.

Parameters:
mixed $check When used as a string, $regex must also be a valid regular expression. As and array: array('check' => value, 'regex' => 'valid regular expression')
string $regex If $check is passed as a string, $regex must also be set to valid regular expression
Returns:
boolean Success public

Definition at line 364 of file validation.php.

References $check, $regex, __(), a(), and getInstance().

Validation::date ( check,
format = 'ymd',
regex = null 
)

Date validation, determines if the string passed is a valid date. keys that expect full month, day and year will validate leap years

Parameters:
string $check a valid date string
mixed $format Use a string or an array of the keys below. Arrays should be passed as array('dmy', 'mdy', etc) Keys: dmy 27-12-2006 or 27-12-06 separators can be a space, period, dash, forward slash mdy 12-27-2006 or 12-27-06 separators can be a space, period, dash, forward slash ymd 2006-12-27 or 06-12-27 separators can be a space, period, dash, forward slash dMy 27 December 2006 or 27 Dec 2006 Mdy December 27, 2006 or Dec 27, 2006 comma is optional My December 2006 or Dec 2006 my 12/2006 separators can be a space, period, dash, forward slash
string $regex If a custom regular expression is used this is the only validation that will occur.
Returns:
boolean Success public

Definition at line 395 of file validation.php.

References $check, $regex, _check(), getInstance(), and r().

Validation::decimal ( check,
places = null,
regex = null 
)

Checks that a value is a valid decimal. If $places is null, the $check is allowed to be a scientific float If no decimal point is found a false will be returned. Both the sign and exponent are optional.

Parameters:
integer $check The value the test for decimal
integer $places if set $check value must have exactly $places after the decimal point
string $regex If a custom regular expression is used this is the only validation that will occur.
Returns:
boolean Success public

Definition at line 464 of file validation.php.

References $check, $regex, and getInstance().

Validation::email ( check,
deep = false,
regex = null 
)

Validates for an email address.

Parameters:
string $check Value to check
boolean $deep Perform a deeper validation (if true), by also checking availability of host
string $regex Regex to use (if none it will use built in regex)
Returns:
boolean Success public

Definition at line 488 of file validation.php.

References $check, $regex, a(), check(), and getInstance().

Validation::equalTo ( check,
comparedTo 
)

Check that value is exactly $comparedTo.

Parameters:
mixed $check Value to check
mixed $comparedTo Value to compare
Returns:
boolean Success public

Definition at line 522 of file validation.php.

References $check.

Validation::extension ( check,
extensions = array('gif', 'jpeg', 'png', 'jpg') 
)

Check that value has a valid file extension.

Parameters:
mixed $check Value to check
array $extensions file extenstions to allow
Returns:
boolean Success public

Definition at line 533 of file validation.php.

References $check.

Validation::file ( check  ) 

Check that value is a file name

Parameters:
mixed $check Value to check public
Todo:
finish implementation

Definition at line 552 of file validation.php.

& Validation::getInstance (  )  [static]

Gets a reference to the Validation object instance

Returns:
object Validation instance public

Definition at line 118 of file validation.php.

Referenced by alphaNumeric(), blank(), cc(), comparison(), custom(), date(), decimal(), email(), Model::invalidFields(), ip(), money(), notEmpty(), phone(), postal(), ssn(), time(), and url().

Validation::inList ( check,
list 
)

Checks if a value is in a given list.

Parameters:
string $check Value to check
array $list List to check against
Returns:
boolean Succcess public

Definition at line 824 of file validation.php.

Validation::ip ( check  ) 

Validation of an IPv4 address.

Parameters:
string $check The string to test.
Returns:
boolean Success public

Definition at line 571 of file validation.php.

References $check, and getInstance().

Referenced by CakeSocket::address(), CakeSocket::addresses(), and CakeSocket::host().

Validation::maxLength ( check,
max 
)

Checks whether the length of a string is smaller or equal to a maximal length..

Parameters:
string $check The string to test
integer $max The maximal string length
Returns:
boolean Success public

Definition at line 597 of file validation.php.

References $check.

Validation::minLength ( check,
min 
)

Checks whether the length of a string is greater or equal to a minimal length.

Parameters:
string $check The string to test
integer $min The minimal string length
Returns:
boolean Success public

Definition at line 585 of file validation.php.

References $check.

Validation::money ( check,
symbolPosition = 'left' 
)

Checks that a value is a monetary amount.

Parameters:
string $check Value to check
string $symbolPosition Where symbol is located (left/right)
Returns:
boolean Success public

Definition at line 609 of file validation.php.

References $check, and getInstance().

Validation::multiple ( check,
options = array() 
)

Validate a multiple select.

Parameters:
mixed $check Value to check
mixed $options Options for the check. Valid options in => provide a list of choices that selections must be made from max => maximun number of non-zero choices that can be made min => minimum number of non-zero choices that can be made
Returns:
boolean Success public

Definition at line 632 of file validation.php.

References $check.

Validation::notEmpty ( check  ) 

Checks that a string contains something other than whitespace

Returns true if string contains something other than whitespace

$check can be passed as an array: array('check' => 'valueToCheck');

Parameters:
mixed $check Value to check
Returns:
boolean Success public

Definition at line 138 of file validation.php.

References $check, check(), and getInstance().

Validation::numeric ( check  ) 

Checks if a value is numeric.

Parameters:
string $check Value to check
Returns:
boolean Succcess public

Definition at line 661 of file validation.php.

References $check.

Validation::phone ( check,
regex = null,
country = 'all' 
)

Check that a value is a valid phone number.

Parameters:
mixed $check Value to check (string or array)
string $regex Regular expression to use
string $country Country code (defaults to 'all')
Returns:
boolean Success public

Definition at line 673 of file validation.php.

References $check, $regex, and getInstance().

Validation::postal ( check,
regex = null,
country = null 
)

Checks that a given value is a valid postal code.

Parameters:
mixed $check Value to check
string $regex Regular expression to use
string $country Country to use for formatting
Returns:
boolean Success public

Definition at line 702 of file validation.php.

References $check, $regex, and getInstance().

Validation::range ( check,
lower = null,
upper = null 
)

Validate that a number is in specified range. if $lower and $upper are not set, will return true if $check is a legal finite on this platform

Parameters:
string $check Value to check
integer $lower Lower limit
integer $upper Upper limit
Returns:
boolean Success public

Definition at line 745 of file validation.php.

References $check.

Validation::ssn ( check,
regex = null,
country = null 
)

Checks that a value is a valid Social Security Number.

Parameters:
mixed $check Value to check
string $regex Regular expression to use
string $country Country
Returns:
boolean Success public

Definition at line 763 of file validation.php.

References $check, $regex, and getInstance().

Validation::time ( check  ) 

Time validation, determines if the string passed is a valid time. Validates time as 24hr (HH:MM) or am/pm ([H]H:MM[a|p]m) Does not allow/validate seconds.

Parameters:
string $check a valid time string
Returns:
boolean Success public

Definition at line 434 of file validation.php.

References $check, and getInstance().

Validation::url ( check,
strict = false 
)

Checks that a value is a valid URL according to http://www.w3.org/Addressing/URL/url-spec.txt

The regex checks for the following component parts: a valid, optional, scheme a valid ip address OR a valid domain name as defined by section 2.3.1 of http://www.ietf.org/rfc/rfc1035.txt with an optional port number an optional valid path an optional query string (get parameters) an optional fragment (anchor tag)

Parameters:
string $check Value to check
boolean $strict Require URL to be prefixed by a valid scheme (one of http(s)/ftp(s)/file/news/gopher)
Returns:
boolean Success public

Definition at line 805 of file validation.php.

References $check, and getInstance().

Validation::userDefined ( check,
object,
method,
args = null 
)

Runs an user-defined validation.

Parameters:
mixed $check value that will be validated in user-defined methods.
object $object class that holds validation method
string $method class method name for validation to run
array $args arguments to send to method
Returns:
mixed user-defined class class method returns public

Definition at line 837 of file validation.php.


Member Data Documentation

Validation::$__pattern

Initial value:

 array(
        'ip' => '(?:(?:25[0-5]|2[0-4][0-9]|(?:(?:1[0-9])?|[1-9]?)[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|(?:(?:1[0-9])?|[1-9]?)[0-9])',
        'hostname' => '(?:[a-z0-9][-a-z0-9]*\.)*(?:[a-z0-9][-a-z0-9]{0,62})\.(?:(?:[a-z]{2}\.)?[a-z]{2,4}|museum|travel)'
    )

Definition at line 77 of file validation.php.

Validation::$check = null

Definition at line 62 of file validation.php.

Referenced by alphaNumeric(), between(), blank(), boolean(), cc(), custom(), date(), decimal(), email(), equalTo(), extension(), ip(), maxLength(), minLength(), money(), multiple(), notEmpty(), numeric(), phone(), postal(), range(), ssn(), time(), and url().

Validation::$country = null

Definition at line 88 of file validation.php.

Validation::$deep = null

Definition at line 95 of file validation.php.

Validation::$errors = array()

Definition at line 110 of file validation.php.

Validation::$regex = null

Definition at line 70 of file validation.php.

Referenced by cc(), custom(), date(), decimal(), email(), phone(), postal(), and ssn().

Validation::$type = null

Definition at line 102 of file validation.php.


The documentation for this class was generated from the following file:
Generated on Sun Nov 22 00:30:57 2009 for CakePHP 1.2.x.x (v1.2.4.8284) by doxygen 1.4.7