1
1
<?php declare (strict_types=1 );
2
2
/**
3
3
* 验证器列表
4
+ *
4
5
* @date 2015.08.04
5
6
* @note 验证数据; 成功则返回预期的类型, 失败返回 false
6
7
* @description INPUT_GET, INPUT_POST, INPUT_COOKIE, INPUT_SERVER, or INPUT_ENV 几个输入数据常量中的值在请求时即固定下来了,
@@ -1135,9 +1136,9 @@ public static function notIn($val, $dict, $strict = false): bool
1135
1136
******************************************************************************/
1136
1137
1137
1138
/**
1138
- * @param mixed $val
1139
+ * @param mixed $val
1139
1140
* @param string|numeric $start
1140
- * @param bool|mixed $strict
1141
+ * @param bool|mixed $strict
1141
1142
*
1142
1143
* @return bool
1143
1144
*/
@@ -1161,9 +1162,9 @@ public static function startWith($val, $start, $strict = true): bool
1161
1162
}
1162
1163
1163
1164
/**
1164
- * @param mixed $val
1165
+ * @param mixed $val
1165
1166
* @param string|numeric $end
1166
- * @param bool|mixed $strict
1167
+ * @param bool|mixed $strict
1167
1168
*
1168
1169
* @return bool
1169
1170
*/
@@ -1191,17 +1192,20 @@ public static function endWith($val, $end, $strict = true): bool
1191
1192
* 校验字段值是否是日期格式
1192
1193
*
1193
1194
* @param string|mixed $val 日期
1195
+ * @param bool|string $sholdGt0
1194
1196
*
1195
1197
* @return boolean
1196
1198
*/
1197
- public static function date ($ val ): bool
1199
+ public static function date ($ val, $ sholdGt0 = false ): bool
1198
1200
{
1199
1201
if (!$ val ) {
1200
1202
return false ;
1201
1203
}
1202
1204
1203
- // strtotime 转换不对,日期格式显然不对。
1204
- return strtotime ((string )$ val ) > 1 ;
1205
+ // strtotime 转换不对,日期格式显然不对
1206
+ $ time = strtotime ((string )$ val );
1207
+
1208
+ return $ sholdGt0 ? $ sholdGt0 > 1 : $ time !== false ;
1205
1209
}
1206
1210
1207
1211
/**
@@ -1225,7 +1229,7 @@ public static function dateEquals($val, $date): bool
1225
1229
* 校验字段值是否是日期并且是否满足设定格式
1226
1230
*
1227
1231
* @param string|mixed $val 日期
1228
- * @param string $format 需要检验的格式数组
1232
+ * @param string $format 需要检验的格式数组
1229
1233
*
1230
1234
* @return bool
1231
1235
*/
@@ -1242,9 +1246,9 @@ public static function dateFormat($val, string $format = 'Y-m-d'): bool
1242
1246
/**
1243
1247
* 字段值必须是给定日期之前的值
1244
1248
*
1245
- * @param string|mixed $val
1249
+ * @param string|mixed $val
1246
1250
* @param string|numeric $beforeDate 若为空,将使用当前时间
1247
- * @param string $symbol allow '<' '<='
1251
+ * @param string $symbol allow '<' '<='
1248
1252
*
1249
1253
* @return bool
1250
1254
*/
@@ -1270,7 +1274,7 @@ public static function beforeDate($val, $beforeDate = '', string $symbol = '<'):
1270
1274
/**
1271
1275
* 字段值必须是小于或等于给定日期的值
1272
1276
*
1273
- * @param string|mixed $val
1277
+ * @param string|mixed $val
1274
1278
* @param string|numeric $beforeDate
1275
1279
*
1276
1280
* @return bool
0 commit comments