'; protected $_error_suffix = '

'; protected $error_string = ''; protected $_safe_form_data = false; /** * Constructor */ function __construct() { parent::__construct(); } // -------------------------------------------------------------------- /** * Match one field to another * * @access public * @param string * @param field * @return bool */ 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; } // -------------------------------------------------------------------- /** * Alpha-numeric with underscores and dashes * * @access public * @param string * @return bool */ public function alphanumunder($str) { return ( ! preg_match("/^([-a-z0-9_])+$/i", $str)) ? false : true; } public function valid_url($str) { $pattern = "|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i"; if ( ! preg_match($pattern, $str)) { return false; } return true; } public function valid_phone($value) { $value = trim($value); if ($value === '') { return true; } else { if (preg_match('/^\(?[0-9]{2,3}\)?[-. ]?[0-9]{3,4}[-. ]?[0-9]{4}$/', $value)) { return preg_replace('/^\(?([0-9]{2,3})\)?[-. ]?([0-9]{3,4})[-. ]?([0-9]{4})$/', '$1-$2-$3', $value); } else { return false; } } } }