Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- * Description of validate
- *
- * @author fabi0
- */
- class validate {
- private $_errors = array();
- private $_data = Null;
- public function setData($data, $data1 = null) {
- $this->_data = $data;
- return $this;
- }
- public function min_length($lenght) {
- if (mb_strlen($this->_data, "utf8") >= $lenght) {
- } else {
- $this->_errors[] = "101";
- }
- return $this;
- }
- public function max_length($lenght) {
- if (mb_strlen($this->_data, "utf8") <= $lenght) {
- } else {
- $this->_errors[] = "102";
- }
- return $this;
- }
- public function string_length($min, $max) {
- if (self::min_length($data, $min) && self::max_length($data, $max)) {
- } else {
- $this->_errors[] = "103";
- }
- }
- public function range($min, $max) {
- if ($data >= $min && $data <= $max) {
- } else {
- $this->_errors[] = "104";
- }
- return $this;
- }
- public function match($value1, $value2) {
- if ($value1 === $value2) {
- } else {
- $this->_errors[] = "105";
- }
- return $this;
- }
- public function email() {
- if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
- } else {
- $this->_errors[] = "106";
- }
- return $this;
- }
- public function required() {
- if ($this->_data == '') {
- $this->_errors[] = "107";
- }
- return $this;
- }
- public function getErrors() {
- return $this->_errors;
- }
- public function clearErrors() {
- $this->_errors = NULL;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement