Geeklog
[ class tree: Geeklog ] [ index: Geeklog ] [ all elements ]

Class: validator

Source Location: /system/classes/validator.class.php

Class Overview


This class allows you to make a validation given input values along with its rules.


Author(s):

  • Akeda Bagus

Variables

Methods



Class Details

[line 43]
This class allows you to make a validation given input values along with its rules.

The process is very similiar with CakePHP Model Validation. Much of code in this class were borrowed from CakePHP Validation Class.




Tags:

author:  Akeda Bagus
see:  http://book.cakephp.org/view/1143/Data-Validation


[ Top ]


Class Variables

$check =  null

[line 50]

Set the the value of methods $check param.



Tags:

access:  public

Type:   string


[ Top ]

$errors = array()

[line 87]

Holds an array of errors messages set in this class.

These are used for debugging purposes




Tags:

access:  public

Type:   array


[ Top ]

$regex =  null

[line 58]

Set to a valid regular expression in the class methods.

Can be set from $regex param also




Tags:

access:  public

Type:   string


[ Top ]

$type =  null

[line 74]

Some class methods use the $type param to determine which validation to perfom in the method



Tags:

access:  public

Type:   string


[ Top ]



Class Methods


static method getInstance [line 94]

static object Validation getInstance( )

Gets a reference to the Validation object instance



Tags:

return:  instance
access:  public


[ Top ]

method alphaNumeric [line 171]

boolean alphaNumeric( mixed $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');




Tags:

return:  Success
access:  public


Parameters:

mixed   $check   Value to check

[ Top ]

method between [line 199]

boolean between( string $check, integer $min, integer $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,




Tags:

return:  Success
access:  public


Parameters:

string   $check   Value to check for length
integer   $min   Minimum value in range (inclusive)
integer   $max   Maximum value in range (inclusive)

[ Top ]

method blank [line 215]

boolean blank( mixed $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');




Tags:

return:  Success
access:  public


Parameters:

mixed   $check   Value to check

[ Top ]

method boolean [line 397]

boolean boolean( string $check)

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



Tags:

return:  Success
access:  public


Parameters:

string   $check   a valid boolean

[ Top ]

method comparison [line 242]

boolean comparison( mixed $check1, [string $operator = null], [integer $check2 = null])

Used to compare 2 numeric values.



Tags:

return:  Success
access:  public


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

[ Top ]

method custom [line 309]

boolean custom( mixed $check, [string $regex = null])

Used when a custom regular expression is needed.



Tags:

return:  Success
access:  public


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

[ Top ]

method date [line 342]

boolean date( string $check, [mixed $format = 'ymd'], [string $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




Tags:

return:  Success
access:  public


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.

[ Top ]

method decimal [line 413]

boolean decimal( integer $check, [integer $places = null], [string $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.



Tags:

return:  Success
access:  public


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.

[ Top ]

method dispatchMethod [line 114]

mixed dispatchMethod( string $method, [array $params = array()])

Calls a method on this object with the given parameters. Provides an OO wrapper for call_user_func_array, and improves performance by using straight method calls in most cases.



Tags:

return:  Returns the result of the method call
access:  public


Parameters:

string   $method   Name of the method to call
array   $params   Parameter list to use when calling $method

[ Top ]

method email [line 438]

boolean email( string $check, [string $regex = null])

Validates for an email address.



Tags:

return:  Success
access:  public


Parameters:

string   $check   Value to check
string   $regex   Regex to use (if none it will use built in regex)

[ Top ]

method equalTo [line 468]

boolean equalTo( mixed $check, mixed $comparedTo)

Check that value is exactly $comparedTo.



Tags:

return:  Success
access:  public


Parameters:

mixed   $check   Value to check
mixed   $comparedTo   Value to compare

[ Top ]

method extension [line 480]

boolean extension( mixed $check, [array $extensions = array('gif', 'jpeg', 'png', 'jpg')])

Check that value has a valid file extension.



Tags:

return:  Success
access:  public


Parameters:

mixed   $check   Value to check
array   $extensions   file extenstions to allow

[ Top ]

method inList [line 771]

boolean inList( string $check, array $list, [boolean $strict = false])

Checks if a value is in a given list.



Tags:

return:  Success
access:  public


Parameters:

string   $check   Value to check
array   $list   List to check against
boolean   $strict   is set to TRUE then will also check the types of the $check.

[ Top ]

method ip [line 506]

boolean ip( string $check, [string $type = 'both'])

Validation 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)




Tags:

return:  Success
access:  public


Parameters:

string   $check   The string to test.
string   $type   The IP Version to test against

[ Top ]

method maxLength [line 578]

boolean maxLength( string $check, integer $max)

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



Tags:

return:  Success
access:  public


Parameters:

string   $check   The string to test
integer   $max   The maximal string length

[ Top ]

method minLength [line 564]

boolean minLength( string $check, integer $min)

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



Tags:

return:  Success
access:  public


Parameters:

string   $check   The string to test
integer   $min   The minimal string length

[ Top ]

method multiple [line 596]

boolean multiple( mixed $check, [mixed $options = array()])

Validate 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




Tags:

return:  Success
access:  public


Parameters:

mixed   $check   Value to check
mixed   $options   Options for the check.

[ Top ]

method notEmpty [line 144]

boolean notEmpty( mixed $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');




Tags:

return:  Success
access:  public


Parameters:

mixed   $check   Value to check

[ Top ]

method numeric [line 627]

boolean numeric( string $check)

Checks if a value is numeric.



Tags:

return:  Success
access:  public


Parameters:

string   $check   Value to check

[ Top ]

method phone [line 639]

boolean phone( mixed $check, [string $regex = null])

Check that a value is a valid phone number.



Tags:

return:  Success
access:  public


Parameters:

mixed   $check   Value to check (string or array)
string   $regex   Regular expression to use

[ Top ]

method range [line 667]

boolean range( string $check, [integer $lower = null], [integer $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




Tags:

return:  Success
access:  public


Parameters:

string   $check   Value to check
integer   $lower   Lower limit
integer   $upper   Upper limit

[ Top ]

method string [line 689]

boolean string( mixed $check)

Checks that a string contains something Returns true if string contains any characters. Function added so old validation would be bypassed.

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




Tags:

return:  Success
access:  public


Parameters:

mixed   $check   Value to check

[ Top ]

method stringOrEmpty [line 717]

boolean stringOrEmpty( mixed $check)

Checks that a string contains either nothing or something Returns true if string contains nothing or any characters. Function added so old validation would be bypassed.

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




Tags:

return:  Success
access:  public


Parameters:

mixed   $check   Value to check

[ Top ]

method time [line 381]

boolean time( string $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.




Tags:

return:  Success
access:  public


Parameters:

string   $check   a valid time string

[ Top ]

method url [line 747]

boolean url( string $check, [boolean $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)




Tags:

return:  Success
access:  public


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)

[ Top ]

method userDefined [line 785]

mixed userDefined( mixed $check, object $object, string $method, [array $args = null])

Runs an user-defined validation.



Tags:

return:  user-defined class class method returns
access:  public


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

[ Top ]

method _check [line 795]

boolean _check( )

Runs a regular expression match.



Tags:

return:  Success of match
access:  protected


[ Top ]

method _extract [line 816]

void _extract( array $params)

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



Tags:

access:  protected


Parameters:

array   $params   Parameters sent to validation method

[ Top ]

method _ipv4 [line 527]

boolean _ipv4( string $check)

Validation of IPv4 addresses.



Tags:

return:  Success
access:  protected


Parameters:

string   $check   IP Address to test

[ Top ]

method _ipv6 [line 545]

boolean _ipv6( string $check)

Validation of IPv6 addresses.



Tags:

return:  Success
access:  protected


Parameters:

string   $check   IP Address to test

[ Top ]


Documentation generated on Sun, 02 Oct 2016 07:56:46 +0000 by phpDocumentor 1.4.3