config = new Config(); } public function ts($ts){ return $this->isIntNumber($ts); } public function id($id){ if(!$this->isIntNumber($id)) return false; if($id <= 0) return false; elseif($id > 0) return true; } public function oneOrZero($number){ if(!$this->isIntNumber($number)) return false; if(($number != 0) && ($number != 1)) return false; return true; } public function noNegativeInteger($number){ if(!$this->isIntNumber($number)) return false; return $number >= 0; } public function count($number){ if(!$this->noNegativeInteger($number)) return false; return true; } public function offset($number){ return $this->isIntNumber($number); } public function name($name){ if(!$this->isString($name, $this->config->nameMinLen, $this->config->nameMaxLen)) return false; if($this->quotes($name)) return false; return true; } public function text($text, $empty = false){ if(($text == "") && ($empty)) return true; return $this->isString($text, $this->config->minText, $this->config->maxText); } public function price($data){ if(!is_numeric($data)) return false; return $data >= 0; } public function phone($phone){ return preg_match("/^\+?(\d){4,13}$/", $phone); // +380931234212 } public function email ($email){ if($this->quotes($email)) return false; return preg_match("/^[a-z0-9]+[a-z0-9\._-]*[a-z0-9]+@([a-z0-9]+[a-z0-9-]\.)*[a-z]{2,}$/i", $email); } public function ids($ids){ if(!is_string($ids)) return false; return preg_match("/^(\d,)*(\d){1}$/", $ids); } private function quotes($text){ $quotes = array("\"","'", "`", """, "'", """, "&apos"); foreach($quotes as $key => $value) if(strpos($text, $value) !== false) return true; return false; } private function isString($text, $min_lenght, $max_lenght){ if(!is_string($text)) return false; if(strlen($text) < $min_lenght) return false; if(strlen($text) > $max_lenght) return false; return true; } private function isIntNumber($number){ if(!is_int($number) && (!is_string($number))) return false; return preg_match("/^-?(([1-9][0-9]*)|(0))$/", $number); } } ?>