Home arrow PHP arrow Page 2 - Building a More Capable Validation Helper Class

Review: the ValidatorHelper class - PHP

In this sixth part of an eight-part series on helper classes, I finish developing the validation helper class created in the previous part. We'll add even more useful validation methods to expand its functionality.

  1. Building a More Capable Validation Helper Class
  2. Review: the ValidatorHelper class
  3. Adding methods for validating IPs, email addresses and URLs
  4. The full source code for the improved validation helper class
By: Alejandro Gervasio
Rating: starstarstarstarstar / 4
August 24, 2009

print this article



As usual, before I proceed to add more methods to the validation helper class developed in the previous part of the series, I will review how it was initially defined.

Below I included for you the complete signature of this sample class, so you can quickly recall how it looked. Here’s the class in question:

class ValidatorHelper


// constructor not implemented

public function __construct(){}


// validate integer

public function validate_int($value, $min, $max)


return filter_var($value, FILTER_VALIDATE_INT, array('options' => array('min_range' => $min, 'max_range' => $max)));



// validate float number

public function validate_float($value)


return filter_var($value, FILTER_VALIDATE_FLOAT);


// validate alphabetic value

public function validate_alpha($value)


return filter_var($value, FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => "/^[a-zA-Z]+$/")));



// validate alphanumeric value

public function validate_alphanum($value)


return filter_var($value, FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => "/^[a-zA-Z0-9]+$/")));



As illustrated above, the “ValidatorHelper” class relies heavily on some PHP filters to validate certain data types, such as float and integer numbers, as well as alphabetic and alphanumeric values. In each case, the method responsible for performing a specific verification simply will return FALSE or an empty string if the inputted parameter is considered invalid.

So far, so good, right? At this stage I’m sure that you’re familiar with the logic that drives the previous validation helper class, which implies that it’s time to continue expanding the class’s current functionality by adding to it a few more checking methods.

However, this process will be accomplished in the course of the following section. So click on the link that appears below and keep on reading.

>>> More PHP Articles          >>> More By Alejandro Gervasio

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: