Преглед изворни кода

V add more filters for integers

Piotr Labudda пре 10 година
родитељ
комит
afcdefc640
1 измењених фајлова са 43 додато и 0 уклоњено
  1. 43 0
      SE/se-lib/V.php

+ 43 - 0
SE/se-lib/V.php

@@ -268,4 +268,47 @@ class V {
 		return !empty($value);
 	}
 
+	public static function filterInteger($value) {// An integer or string with integer value
+		if (is_int($value)) {
+			return true;
+		} else if (is_string($value)) {
+			if ((string)(int)$value === $value) {
+				return true;
+			}
+		}
+		return false;
+	}
+	public static function filterNegativeInteger($value) {// An integer containing only negative values (..,-2,-1)
+		if (V::filterInteger($value)) {
+			if (intval($value) < 0) {
+				return true;
+			}
+		}
+		return false;
+	}
+	public static function filterNonNegativeInteger($value) {// An integer containing only non-negative values (0,1,2,..)
+		if (V::filterInteger($value)) {
+			if (intval($value) >= 0) {
+				return true;
+			}
+		}
+		return false;
+	}
+	public static function filterNonPositiveInteger($value) {// An integer containing only non-positive values (..,-2,-1,0)
+		if (V::filterInteger($value)) {
+			if (intval($value) <= 0) {
+				return true;
+			}
+		}
+		return false;
+	}
+	public static function filterPositiveInteger($value) {// An integer containing only positive values (1,2,..)
+		if (V::filterInteger($value)) {
+			if (intval($value) > 0) {
+				return true;
+			}
+		}
+		return false;
+	}
+
 }