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.
blog comments powered by Disqus |
|
|
|
|
|
|
|