Location: PHPKode > scripts > QValidation > qvalidation/Validation/DataType/Common.php
<?php


class Validation_DataType_Common implements ValidInterface {

	private $ver = false;

	public function __construct(){
		$v = explode(".",phpversion());
		if($v[0]==5 and $v[1]>=2 and $v[2]>=0) $this->ver = true;
		else $this->ver = false;
	}

	public static function getInstance(){
		return new Validation_DataType_Common;
	}

	/**
	 *
	 * @param mixed $value
	 * @return bool
	 */
	public static function isNull($value) {
		if(strlen($value) == 1 and is_string($value) and ($value==0 or $value=='0')) {
			return true;
		} else {
			return (is_null($value) or empty($value) or !strcmp($value,'') ? true : false);
		}
	}

	private static function validFilter($value, $filter, $options = null) {
		if($this->ver) {
			return (filter_var($value, $filter, $options)?true:false);
		} else {
			throw new Execption("filter_var is not supported.");
			return false;
		}
	}

	public static function validateBool($value) {
		return self::validFilter($value, FILTER_VALIDATE_BOOLEAN, null);
	}

	public static function validateFloat($value) {
		return self::validFilter($value, FILTER_VALIDATE_FLOAT, null);
	}

	public static function validateEmail($value) {
		return self::validFilter($value, FILTER_VALIDATE_EMAIL, null);
	}

	public static function validateIP4($value) {
		return self::validFilter($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
	}

	public static function validateIP6($value) {
		return self::validFilter($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6);
	}

	public static function validateIPNoPrivRange($value) {
		return self::validFilter($value, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE);
	}

	public static function validateIPNoResRange($value) {
		return self::validFilter($value, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE);
	}

	public static function validateUrl($value) {
		return self::validFilter($value, FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED);
	}

	public static function validateUrlHostRequired($value) {
		return self::validFilter($value, FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED);
	}

	public static function validateUrlPathRequired($value) {
		return self::validFilter($value, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED);
	}

	public static function validateUrlQueryRequired($value) {
		return self::validFilter($value, FILTER_VALIDATE_URL, FILTER_FLAG_QUERY_REQUIRED);
	}


}
Return current item: QValidation