Validation Class Info:
- Class Declaration:
class Validation extends Object
- File name:
- cake/libs/validation.php
- Description:
Offers different validation methods.
- Class Inheritance
- Package
- cake
- Subpackage
- cake.cake.libs
- Since
CakePHP v 1.2.0.3830
Properties:
-
check string
Set the value of methods $check param.
-
country string
Some class methods use a country to determine proper validation. This can be passed to methods in the $country param
-
deep string
Some class methods use a deeper validation when set to true
-
errors array
Holds an array of errors messages set in this class. These are used for debugging purposes
-
regex string
Set to a valid regular expression in the class methods. Can be set from $regex param also
-
type string
Some class methods use the $type param to determine which validation to perfom in the method
Method Summary:
- alphaNumeric( $check )
- between( $check, $min, $max )
- blank( $check )
- boolean( $check )
- cakeError( $method, $messages = array ( ) )
- cc( $check, $type = 'fast', $deep = false, $regex = NULL )
- _check( )
- comparison( $check1, $operator = NULL, $check2 = NULL )
- __construct( )
- custom( $check, $regex = NULL )
- date( $check, $format = 'ymd', $regex = NULL )
- decimal( $check, $places = NULL, $regex = NULL )
- dispatchMethod( $method, $params = array ( ) )
- email( $check, $deep = false, $regex = NULL )
- equalTo( $check, $comparedTo )
- extension( $check, $extensions = array ( 0 => 'gif', 1 => 'jpeg', 2 => 'png', 3 => 'jpg', ) )
- _extract( $params )
- getInstance( )
- inList( $check, $list )
- ip( $check, $type = 'both' )
- _ipv4( $check )
- _ipv6( $check )
- log( $msg, $type = 2 )
- _luhn( )
- maxLength( $check, $max )
- minLength( $check, $min )
- money( $check, $symbolPosition = 'left' )
- multiple( $check, $options = array ( ) )
- notEmpty( $check )
- numeric( $check )
- Object( )
- _pass( $method, $check, $classPrefix )
- _persist( $name, $return, $object, $type = NULL )
- phone( $check, $regex = NULL, $country = 'all' )
- __populateIp( )
- postal( $check, $regex = NULL, $country = NULL )
- range( $check, $lower = NULL, $upper = NULL )
- requestAction( $url, $extra = array ( ) )
- _savePersistent( $name, $object )
- _set( $properties = array ( ) )
- ssn( $check, $regex = NULL, $country = NULL )
- _stop( $status = 0 )
- time( $check )
- toString( )
- url( $check, $strict = false )
- userDefined( $check, $object, $method, $args = NULL )
- uuid( $check )
alphaNumeric
topChecks 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 required
Value to check
-
- Method defined in:
- cake/libs/validation.php on line 149
- Return
boolean Success
- Access
public
between
topChecks 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 required
Value to check for length
-
integer $min required
Minimum value in range (inclusive)
-
integer $max required
Maximum value in range (inclusive)
-
- Method defined in:
- cake/libs/validation.php on line 176
- Return
boolean Success
- Access
public
blank
topReturns 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 required
Value to check
-
- Method defined in:
- cake/libs/validation.php on line 192
- Return
boolean Success
- Access
public
boolean
topBoolean validation, determines if value passed is a boolean integer or true/false.
- Parameters:
-
-
string $check required
a valid boolean
-
- Method defined in:
- cake/libs/validation.php on line 443
- Return
boolean Success
- Access
public
cakeError
topUsed to report user friendly errors. If there is a file app/error.php or app/app_error.php this file will be loaded error.php is the AppError class it should extend ErrorHandler class.
- Parameters:
-
-
string $method required
Method to be called in the error class (AppError or ErrorHandler classes)
-
array $messages optional array ( )
Message that is to be displayed by the error class
-
- Method defined in:
- cake/libs/object.php on line 187
- Return
error message
- Access
public
cc
topValidation of credit card numbers. Returns true if $check is in the proper credit card format.
- Parameters:
-
-
mixed $check required
credit card number to validate
-
mixed $type optional 'fast'
'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 optional false
set to true this will check the Luhn algorithm of the credit card.
-
string $regex optional NULL
A custom regex can also be passed, this will be used instead of the defined regex values
-
- Method defined in:
- cake/libs/validation.php on line 219
- Return
boolean Success
- Access
public
- See
_check
topRuns a regular expression match.
- Method defined in:
- cake/libs/validation.php on line 944
- Return
boolean Success of match
- Access
protected
comparison
topUsed to compare 2 numeric values.
- Parameters:
-
-
mixed $check1 required
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 optional NULL
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 optional NULL
only needed if $check1 is a string
-
- Method defined in:
- cake/libs/validation.php on line 297
- Return
boolean Success
- Access
public
__construct
topClass constructor, overridden in descendant classes.
- Method defined in:
- cake/libs/object.php on line 54
custom
topUsed when a custom regular expression is needed.
As and array: array('check' => value, 'regex' => 'valid regular expression')
- Parameters:
-
-
mixed $check required
When used as a string, $regex must also be a valid regular expression.
-
string $regex optional NULL
If $check is passed as a string, $regex must also be set to valid regular expression
-
- Method defined in:
- cake/libs/validation.php on line 357
- Return
boolean Success
- Access
public
date
topDate validation, determines if the string passed is a valid date. keys that expect full month, day and year will validate leap years
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
- Parameters:
-
-
string $check required
a valid date string
-
mixed $format optional 'ymd'
Use a string or an array of the keys below. Arrays should be passed as array('dmy', 'mdy', etc)
-
string $regex optional NULL
If a custom regular expression is used this is the only validation that will occur.
-
- Method defined in:
- cake/libs/validation.php on line 389
- Return
boolean Success
- Access
public
decimal
topChecks 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 required
The value the test for decimal
-
integer $places optional NULL
if set $check value must have exactly $places after the decimal point
-
string $regex optional NULL
If a custom regular expression is used this is the only validation that will occur.
-
- Method defined in:
- cake/libs/validation.php on line 458
- Return
boolean Success
- Access
public
dispatchMethod
topCalls a method on this object with the given parameters. Provides an OO wrapper
for call_user_func_array
- Parameters:
-
-
string $method required
Name of the method to call
-
array $params optional array ( )
Parameter list to use when calling $method
-
- Method defined in:
- cake/libs/object.php on line 107
- Return
mixed Returns the result of the method call
- Access
public
Validates for an email address.
- Parameters:
-
-
string $check required
Value to check
-
boolean $deep optional false
Perform a deeper validation (if true), by also checking availability of host
-
string $regex optional NULL
Regex to use (if none it will use built in regex)
-
- Method defined in:
- cake/libs/validation.php on line 483
- Return
boolean Success
- Access
public
equalTo
topCheck that value is exactly $comparedTo.
- Parameters:
-
-
mixed $check required
Value to check
-
mixed $comparedTo required
Value to compare
-
- Method defined in:
- cake/libs/validation.php on line 523
- Return
boolean Success
- Access
public
extension
topCheck that value has a valid file extension.
- Parameters:
-
-
mixed $check required
Value to check
-
array $extensions optional array ( 0 => 'gif', 1 => 'jpeg', 2 => 'png', 3 => 'jpg', )
file extenstions to allow
-
- Method defined in:
- cake/libs/validation.php on line 535
- Return
boolean Success
- Access
public
_extract
topGet the values to use when value sent to validation method is an array.
- Parameters:
-
-
array $params required
Parameters sent to validation method
-
- Method defined in:
- cake/libs/validation.php on line 963
- Return
void
- Access
protected
getInstance
topGets a reference to the Validation object instance
- Method defined in:
- cake/libs/validation.php on line 100
- Return
object Validation instance
- Access
public
- Static
inList
topChecks if a value is in a given list.
- Parameters:
-
-
string $check required
Value to check
-
array $list required
List to check against
-
- Method defined in:
- cake/libs/validation.php on line 895
- Return
boolean Succcess
- Access
public
ip
topValidation of an IP address.
Valid IP version strings for type restriction are: - both: Check both IPv4 and IPv6, return true if the supplied address matches either version - IPv4: Version 4 (Eg: 127.0.0.1, 192.168.10.123, 203.211.24.8) - IPv6: Version 6 (Eg: ::1, 2001:0db8::1428:57ab)
- Parameters:
-
-
string $check required
The string to test.
-
string $type optional 'both'
The IP Version to test against
-
- Method defined in:
- cake/libs/validation.php on line 561
- Return
boolean Success
- Access
public
_ipv4
topValidation of IPv4 addresses.
- Parameters:
-
-
string $check required
IP Address to test
-
- Method defined in:
- cake/libs/validation.php on line 581
- Return
boolean Success
- Access
protected
_ipv6
topValidation of IPv6 addresses.
- Parameters:
-
-
string $check required
IP Address to test
-
- Method defined in:
- cake/libs/validation.php on line 598
- Return
boolean Success
- Access
protected
log
topConvience method to write a message to CakeLog. See CakeLog::write() for more information on writing to logs.
- Parameters:
-
-
string $msg required
Log message
-
integer $type optional 2
Error type constant. Defined in app/config/core.php.
-
- Method defined in:
- cake/libs/object.php on line 148
- Return
boolean Success of log write
- Access
public
_luhn
topLuhn algorithm
- Method defined in:
- cake/libs/validation.php on line 991
- See
http://en.wikipedia.org/wiki/Luhn_algorithm
- Return
boolean Success
- Access
protected
maxLength
topChecks whether the length of a string is smaller or equal to a maximal length..
- Parameters:
-
-
string $check required
The string to test
-
integer $max required
The maximal string length
-
- Method defined in:
- cake/libs/validation.php on line 629
- Return
boolean Success
- Access
public
minLength
topChecks whether the length of a string is greater or equal to a minimal length.
- Parameters:
-
-
string $check required
The string to test
-
integer $min required
The minimal string length
-
- Method defined in:
- cake/libs/validation.php on line 616
- Return
boolean Success
- Access
public
money
topChecks that a value is a monetary amount.
- Parameters:
-
-
string $check required
Value to check
-
string $symbolPosition optional 'left'
Where symbol is located (left/right)
-
- Method defined in:
- cake/libs/validation.php on line 642
- Return
boolean Success
- Access
public
multiple
topValidate a multiple select.
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
- Parameters:
-
-
mixed $check required
Value to check
-
mixed $options optional array ( )
Options for the check.
-
- Method defined in:
- cake/libs/validation.php on line 668
- Return
boolean Success
- Access
public
notEmpty
topChecks 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 required
Value to check
-
- Method defined in:
- cake/libs/validation.php on line 121
- Return
boolean Success
- Access
public
numeric
topChecks if a value is numeric.
- Parameters:
-
-
string $check required
Value to check
-
- Method defined in:
- cake/libs/validation.php on line 698
- Return
boolean Succcess
- Access
public
Object
topA hack to support __construct() on PHP 4 Hint: descendant classes have no PHP4 class_name() constructors, so this constructor gets called first and calls the top-layer __construct() which (if present) should call parent::__construct()
- Method defined in:
- cake/libs/object.php on line 43
- Return
Object
_pass
topAttempts to pass unhandled Validation locales to a class starting with $classPrefix
and ending with Validation. For example $classPrefix = 'nl', the class would be
NlValidation.
- Parameters:
-
-
string $method required
The method to call on the other class.
-
mixed $check required
The value to check or an array of parameters for the method to be called.
-
string $classPrefix required
The prefix for the class to do the validation.
-
- Method defined in:
- cake/libs/validation.php on line 924
- Return
mixed Return of Passed method, false on failure
- Access
protected
_persist
topChecks for a persistent class file, if found file is opened and true returned If file is not found a file is created and false returned If used in other locations of the model you should choose a unique name for the persistent file There are many uses for this method, see manual for examples
- Parameters:
-
-
string $name required
name of the class to persist
-
$return required
-
string $object required
the object to persist
-
$type optional NULL
-
- Method defined in:
- cake/libs/object.php on line 218
- Return
boolean Success
- Access
protected
- Todo
add examples to manual
phone
topCheck that a value is a valid phone number.
- Parameters:
-
-
mixed $check required
Value to check (string or array)
-
string $regex optional NULL
Regular expression to use
-
string $country optional 'all'
Country code (defaults to 'all')
-
- Method defined in:
- cake/libs/validation.php on line 711
- Return
boolean Success
- Access
public
postal
topChecks that a given value is a valid postal code.
- Parameters:
-
-
mixed $check required
Value to check
-
string $regex optional NULL
Regular expression to use
-
string $country optional NULL
Country to use for formatting
-
- Method defined in:
- cake/libs/validation.php on line 745
- Return
boolean Success
- Access
public
range
topValidate 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 required
Value to check
-
integer $lower optional NULL
Lower limit
-
integer $upper optional NULL
Upper limit
-
- Method defined in:
- cake/libs/validation.php on line 794
- Return
boolean Success
- Access
public
requestAction
topCalls a controller's method from any location. Can be used to connect controllers together or tie plugins into a main application. requestAction can be used to return rendered views or fetch the return value from controller actions.
- Parameters:
-
-
mixed $url required
String or array-based url.
-
array $extra optional array ( )
if array includes the key "return" it sets the AutoRender to true.
-
- Method defined in:
- cake/libs/object.php on line 80
- Return
mixed Boolean true or false on success/failure, or contents of rendered action if 'return' is set in $extra.
- Access
public
_savePersistent
topYou should choose a unique name for the persistent file
There are many uses for this method, see manual for examples
- Parameters:
-
-
string $name required
name used for object to cache
-
object $object required
the object to persist
-
- Method defined in:
- cake/libs/object.php on line 247
- Return
boolean true on save, throws error if file can not be created
- Access
protected
_set
topAllows setting of multiple properties of the object in a single line of code. Will only set properties that are part of a class declaration.
- Parameters:
-
-
array $properties optional array ( )
An associative array containing properties and corresponding values.
-
- Method defined in:
- cake/libs/object.php on line 166
- Return
void
- Access
protected
ssn
topChecks that a value is a valid Social Security Number.
- Parameters:
-
-
mixed $check required
Value to check
-
string $regex optional NULL
Regular expression to use
-
string $country optional NULL
Country
-
- Method defined in:
- cake/libs/validation.php on line 813
- Return
boolean Success
- Access
public
_stop
topStop execution of the current script. Wraps exit() making testing easier.
- Parameters:
-
-
$status optional 0
-
- Method defined in:
- cake/libs/object.php on line 135
- Return
void
- Access
public
time
topTime 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 required
a valid time string
-
- Method defined in:
- cake/libs/validation.php on line 428
- Return
boolean Success
- Access
public
toString
topObject-to-string conversion. Each class can override this method as necessary.
- Method defined in:
- cake/libs/object.php on line 64
- Return
string The name of this class
- Access
public
url
topChecks 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 required
Value to check
-
boolean $strict optional false
Require URL to be prefixed by a valid scheme (one of http(s)/ftp(s)/file/news/gopher)
-
- Method defined in:
- cake/libs/validation.php on line 873
- Return
boolean Success
- Access
public
userDefined
topRuns an user-defined validation.
- Parameters:
-
-
mixed $check required
value that will be validated in user-defined methods.
-
object $object required
class that holds validation method
-
string $method required
class method name for validation to run
-
array $args optional NULL
arguments to send to method
-
- Method defined in:
- cake/libs/validation.php on line 909
- Return
mixed user-defined class class method returns
- Access
public
uuid
topChecks that a value is a valid uuid - http://tools.ietf.org/html/rfc4122
- Parameters:
-
-
string $check required
Value to check
-
- Method defined in:
- cake/libs/validation.php on line 848
- Return
boolean Success
- Access
public