|
@@ -56,6 +56,8 @@ class Validate
|
|
|
'email' => '邮箱',
|
|
|
'idcode' => '身份证',
|
|
|
'number' => '数字',
|
|
|
+ 'float' => '浮点数',
|
|
|
+ 'decimal' => '小数',
|
|
|
'http' => '网址',
|
|
|
'qq' => 'qq',
|
|
|
'postcode' => '邮编',
|
|
@@ -471,4 +473,29 @@ class Validate
|
|
|
{
|
|
|
return in_array($str, $sets);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 是否是浮点数
|
|
|
+ *
|
|
|
+ * @param float $str
|
|
|
+ * @return int
|
|
|
+ */
|
|
|
+ public function float($str)
|
|
|
+ {
|
|
|
+ return preg_match("/^(([1-9]\d*)|0)(\.\d{1,})?$/", $str);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 匹配小数
|
|
|
+ *
|
|
|
+ * @param decimal $str
|
|
|
+ * @param $decimal
|
|
|
+ * @return int
|
|
|
+ */
|
|
|
+ public function decimal($str, $decimal)
|
|
|
+ {
|
|
|
+ $decimalArr = explode(',', $decimal);
|
|
|
+
|
|
|
+ return preg_match("/^(([1-9]\d*)|0{1,". $decimalArr[0] ."})(\.\d{".$decimalArr[1]."})?$/", $str);
|
|
|
+ }
|
|
|
}
|