Last active
August 29, 2015 14:19
-
-
Save tonholis/58d8b468ded6b484ac3a to your computer and use it in GitHub Desktop.
MY_Form_validation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php defined('BASEPATH') OR exit('No direct script access allowed'); | |
class MY_Form_validation extends CI_Form_validation | |
{ | |
function __construct() | |
{ | |
parent::__construct(); | |
log_message('debug', "MY_Form_validation Class Initialized"); | |
} | |
// Usage ex: is_unique[users.email.id.' . $user_id . ']' | |
public function is_unique($str, $field) | |
{ | |
if (substr_count($field, '.') == 3) { | |
list($table, $field, $id_field, $id_val) = explode('.', $field); | |
$query = $this->CI->db->limit(1)->where($field, $str)->where($id_field . ' != ', $id_val)->get($table); | |
} else { | |
list($table, $field) = explode('.', $field); | |
$query = $this->CI->db->limit(1)->get_where($table, array($field => $str)); | |
} | |
return $query->num_rows() === 0; | |
} | |
/** | |
* Numeric/Decimal number | |
* | |
* @access public | |
* @param string | |
* @return bool | |
*/ | |
public function numeric($str) | |
{ | |
return (bool)preg_match('/[0-9]+([0-9]+\.)?(\,[0-9]+)?/', $str); | |
} | |
/** | |
* Validate brazilian date format | |
* | |
* @access public | |
* @param string | |
* @return bool | |
*/ | |
public function valid_brdate($str = '') | |
{ | |
if (empty($str)) | |
return false; | |
list($day, $month, $year) = explode('/', $str); | |
return checkdate($month, $day, $year); | |
} | |
public function db_decimal($str = '') | |
{ | |
return decimal2db($str); | |
} | |
public function db_date($str = '') | |
{ | |
return date2db($str); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment