Validator

List of Validators

The Zoop Validator Component is used by a number of the other components, particularly guiControl and Forms.

It provides type based validation that can be used to validate user_input, or anything else you can think of.

Here is a table of the current validators:

Type PHP JS Notes
Phone x x US phone only.
Length x x Accepts min and max params.
Quantity x For quantity in an array (like boxes checked). Accepts min and max params.
EqualTo x Requires equal_id param (id of another field).
Int x x Accepts min and max params.
Float x x Accepts min and max params.
Numeric x x Accepts min and max params.
AlphaNumeric x x
Money x x
Zip x x Canadian or US formatted Zip (postal) code.
Email x x
Domain x doesn't start with http:// or https://
Url x x starts with http:// or https://
IP x
Password x Validates for a secure password... 1 UC, 2 LC and 1 Num and Length > 6
SSN x
RegExp x Requires Parameter RegExp Which needs to be a valid preg style Expression
DbUnique x Requires Parameters table and field. It will check the table in the default sql connection to see if a duplicate value exists in that table.
Date x Accepts Parameter format. Accepted values for format are "writeout", "us", "european", "univeral".

Using Validate

All the validation functions are statically callable. They follow the following pattern, using Int as an example.

The Call:

Validator::validateInt($value, array('min' => 3, 'max' => 7));

Returns an array ($result), with the following structure:

$result['result'] = false; // or true depending on validation
$result['message'] = "Message to Display to the User when False";

GuiControls and Forms both use integrate the use of validator. Simple by defining the validate parameters of either, you will be using validator.

There are also a handful of special functions to help you in implementing validation in your code.

Special Functions

Validate

validate wrapper for the functions in this class.

The validate array must have 'type' => $type set for this to work. The type is any found in the above table (and php able).

This function also permits 'required' as a parameter in the array(). Without required set to true, a value will validate as true if it is either empty, null, or validates.

Example:

Validator::validate($value, array('type' => 'email', 'required' => 'true'));

boolValidate

validate wrapper for the functions in this class. Works like validate, but returns a boolean (true / false) value rather than an array.

The validate array must have 'type' => $type set for this to work. The type is any found in the above table (and php able).

Example:

Validator::boolValidate($value, array('type' => 'email'));

validateStack

This function will validate more than one validator, stacked in order one at a time. Permits validating things like Alpahnumeric & Length together for example.

It will return as soon as one of the validators fails. This is particularly useful if one of the validators performs a sql check.

The validate array must have 'validators' => array of individual "validate" arrays  set for this to work.validate wrapper for the functions in this class.

Example:

Validator::validateStack($value, array('required' => true, 
   'validators' =>
      array(
	array('type' => 'AlphaNumeric'),
	array('type' => 'length', "min" => 4, "max" => 20),
	array('type' => 'dbUnique', 'field' => 'username', 'table' => 'users')
 )));

validateMerge

This function will validate more than one validator, stacked in order one at a time. Permits validating things like Alpahnumeric & Length together for example.

It will perform all validations before it returns the combined results.

The validate array must have 'validators' => array of individual "validate" arrays  set for this to work.validate wrapper for the functions in this class.

Example:

Validator::validateMerge($value, array('required' => true, 
   'validators' =>
      array(
	array('type' => 'AlphaNumeric'),
	array('type' => 'length', "min" => 4, "max" => 20),
	array('type' => 'dbUnique', 'field' => 'username', 'table' => 'users')
 )));

you did a great job, man.

you did a great job, man. some of these code lines are of a particular use for me.
itransition software development

kollo 06 Dec 2011

That's a really great help.

That's a really great help. Thanks man, I bookmarked.
Book a home online for your summer beach vacation in Europe.

suzettech 07 Dec 2011

i was looking for the based

i was looking for the based validation for user input.
Bollywood Movies

walter1 16 Dec 2011

What an awesome publish that

What an awesome publish that I have ever come through. It gives the details that I was really in search of the last weeks time and I am really fulfilled with this publish. Need more like this. hcg diet canada

bobreel 04 Feb 2012

broadband phone

Some more point can be elaborate through this blog. Similar point can be polished using your content. Nicely posted blog.

broadband phone

ericstuart1006 23 Dec 2011

The following article

The following article actually established my very own little brown eyes towards the several merchants which usually organizations currently have by means of internet marketing.i like to read informative blogs and this blog is also so good and helpful.thanks for taking time to discus this topic...order entry outsourcing

bobreel 03 Feb 2012