Skip to content

Commit

Permalink
Updated validation helper to be mostly PSR compliant.
Browse files Browse the repository at this point in the history
  • Loading branch information
brodkin committed Oct 5, 2012
1 parent e5b234b commit 2c067e6
Showing 1 changed file with 51 additions and 7 deletions.
58 changes: 51 additions & 7 deletions helpers/glib_validation_helper.php
@@ -1,13 +1,34 @@
<?php

/**
* Validation Helper
*
* PHP Version 5.3
*
* @category Helper
* @package Codeigniter
* @author Brodkin CyberArts <support@brodkinca.com>
* @copyright 2012 Brodkin CyberArts.
* @license All rights reserved.
* @version GIT: $Id$
* @link http://brodkinca.com/
*/

/**
* Validate Email Address
*
* @param string $str String containing email address
*
* @return boolean
*/
function is_email($str)
{
$CI =& get_instance();
$CI->load->library('form_validation');
$CI->form_validation->set_message('is_email', '%s must be a valid email address.');
if (
strlen($str) <= 256
&& preg_match('/([A-Z0-9._%+-]+)@([A-Z0-9.-]+\.[A-Z]{2,4})/i',$str,$part)
&& preg_match('/([A-Z0-9._%+-]+)@([A-Z0-9.-]+\.[A-Z]{2,4})/i', $str, $part)
&& isset($part[1],$part[2])
&& strlen($part[1]) <= 64
&& strlen($part[2]) <= 255
Expand All @@ -18,6 +39,13 @@ function is_email($str)
}
}

/**
* Validate Telephone Number
*
* @param string $str String containing telephone number
*
* @return boolean
*/
function is_tel($str)
{
$CI =& get_instance();
Expand All @@ -33,22 +61,38 @@ function is_tel($str)
}
}

function min_value ($val,$min)
/**
* Validate if value is greater than or equal to minimum
*
* @param int $val Test value
* @param int $min Minimum value
*
* @return boolean
*/
function min_value ($val, $min)
{
settype($min, "float");
$CI =& get_instance();
$CI->load->library('form_validation');
$CI->form_validation->set_message('min_value', '%s must be at least '.$min.'.');
if ($min <= $val) return TRUE;
else return FALSE;
if ($min <= $val) return true;
else return false;
}

function max_value ($val,$max)
/**
* Validate if value is less than or equal to maximum
*
* @param int $val Test value
* @param int $max Maximum value
*
* @return boolean
*/
function max_value ($val, $max)
{
settype($max, "float");
$CI =& get_instance();
$CI->load->library('form_validation');
$CI->form_validation->set_message('max_value', '%s must not exceed '.$max.'.');
if ($val > $max) return FALSE;
else return TRUE;
if ($val >= $max) return false;
else return true;
}

0 comments on commit 2c067e6

Please sign in to comment.