Class: ValidateText

Source Location: /validate.php

Class Overview [line 31]

Validation class for information in PHP.



  • 1.0.0

    For full documentation and updates please visit:

    Description: This class should be used statically to validate a set of textual inputs as specified by the user. Once called, it will provide an array of any errors which ocurred throughout validation. Please refer to the 'validate' function for more information.


  • Andrew Judd, 2010




Inherited Variables

Inherited Constants

Inherited Methods

Class Details

Validation class for information in PHP.

This database class is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

This database class is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.


[ Top ]

Class Variables

Class Methods

static validate

static array validate( array 0)

[line 138]

This function is the only function which needs to be called for this class.

It will complete all of the processing of the information passed into it as parameters and then return an array containing all of the issues with the specified data. If there are no problems, this function will return NULL.

For each parameter the following values are possible:

  • value - the value which needs to be validated
  • field - the name that this data will be referenced by
  • length - specify the length of the information stored.
  • string - specify specific information about the actual string (i.e. what is allowed and what is not)
  • integer - a number without any decimal points (defaults to signed)
  • decimal - a number with decimal places (defaults to signed)
  • real - same as decimal

Please Note: The 'value' and 'field' fields must always be in the array or else the value will provide an error.
Please Note: All parameters are case-sensitive.

Some of the validation fields may require additional information when than what is originally provided. To do this, add an additional array can be associated with each of the options (as listed below) to make the validation more thorough.

Options with Extra Parameters:

length (a minimum of 1 of these parameters must be provided):

  • min - The minimum length that the value is allowed to have.
  • max - The maximum length that the value is allowed to have.

string (a minimum of 1 of these parameters must be provided):

  • alphabetic - Only allows letters of the alphabet in the text
  • alphanumeric - Only allows letters of the alphabet and numbers in the text
  • anything - Allows any kind of characters in the string
  • spaces - Allows for spaces to be in any of the text fields (combines with the three previous options)


  • min - The minimum value that the number is allowed to be.
  • max - The maximum value that the number is allowed to be.


  • min - The minimum value that the number is allowed to be.
  • max - The maximum value that the number is allowed to be.

Sample usage of this function:

 $variable1 = 'bob';
 $variable2 = 'howdy';
 ValidateText::validate ( array ( 'value' => $variable1, 'field' => '1', 'length' => array ( 'min' => 5 ) ),
			array ( 'value' => $variable2, 'field' => '2', 'length' => array ( 'min' => 5, 'max' => 10 )


  • return - Either an array of error messages about what is incorrect about the data, or NULL if there are no problems with the data.
  • access - public


  • array 0 - args1-X - The arrays of values which will be validated against various criteria.

[ Top ]

Class Constants

ERROR_INVALID_CHARACTERS_IN_STRING =  'The provided string \'<em>%v</em>\' contains some invalid charaters for field <em>%f</em>.'

[line 43]

[ Top ]

ERROR_INVALID_DECIMAL =  'The decimal value provided (<em>%v</em>) was invalid for field <em>%f</em>.'

[line 48]

[ Top ]

ERROR_INVALID_INTEGER =  'The integer provided (<em>%v</em>) was invalid for field <em>%f</em>.'

[line 45]

[ Top ]

ERROR_INVALID_MAXIMUM_VALUE =  'The provided maximum value (%v) for the field \'<em>%f</em>\' is invalid.'

[line 42]

[ Top ]

ERROR_INVALID_MINIMUM_VALUE =  'The provided minimum value (%v) for the field \'<em>%f</em>\' is invalid.'

[line 40]

[ Top ]

ERROR_INVALID_OPTIONS_TYPE =  'Invalid options provided for parameter <em>%p</em>.'

[line 34]

[ Top ]

ERROR_INVALID_VALIDATION_OPTION =  'The provided validation option \'<em>%m</em>\' for value <em>%v</em> does not exist.'

[line 38]

[ Top ]

ERROR_MAXIMUM_LENGTH_EXCEEDED =  'The text \'<em>%v</em>\' exceeds the maximum length of %p for field <em>%f</em>.'

[line 41]

[ Top ]

ERROR_MAXIMUM_VALUE_EXCEEDED =  'The value provided <em>%v</em> exceeds the maximum required value <em>%p</em> for field <em>%f</em>.'

[line 47]

[ Top ]

ERROR_MINIMUM_LENGTH_NOT_MET =  'The text \'<em>%v</em>\' does not meet the minimum length requirement of %p for field <em>%f</em>.'

[line 39]

[ Top ]

ERROR_MINIMUM_VALUE_NOT_MET =  'The value provided <em>%v</em> is less than the minimum required value <em>%p</em> for field <em>%f</em>.'

[line 46]

[ Top ]

ERROR_NO_FIELD_SPECIFIED =  'No field to validate for parameter <em>%p</em>.'

[line 36]

[ Top ]

ERROR_NO_PARAMETERS_FOR_STRING =  'The string \'<em>%v</em>\' was to be validated for field <em>%f</em>, however no validation options were provided.'

[line 44]

[ Top ]

ERROR_NO_REQUIREMENTS =  'No validation requirements for parameter <em>%p</em>.'

[line 37]

[ Top ]

ERROR_NO_VALUE_SPECIFIED =  'No value to validate for parameter <em>%p</em>.'

[line 35]

[ Top ]


[line 52]

[ Top ]


[line 53]

[ Top ]


[line 54]

[ Top ]


[line 55]

[ Top ]


[line 56]

[ Top ]


[line 57]

[ Top ]

REGEX_SIGNED_DECIMAL =  '/^(\+|\-)?[0-9]*\.?[0-9]+$/'

[line 63]

[ Top ]

REGEX_SIGNED_INTEGER =  '/^(\+|\-)?[0-9]+$/'

[line 61]

[ Top ]

REGEX_UNSIGNED_DECIMAL =  '/^[0-9]*\.[0-9]+$/'

[line 62]

[ Top ]


[line 60]

[ Top ]

Documentation generated on Sun, 20 Dec 2009 17:03:29 -0500 by phpDocumentor 1.4.3