@@ -277,28 +277,6 @@ public static function range($val, $min = null, $max = null)
277277 return self ::size ($ val , $ min , $ max );
278278 }
279279
280- /**
281- * 必须是等于给定值
282- * @param mixed $val
283- * @param mixed $excepted
284- * @return bool
285- */
286- public static function mustBe ($ val , $ excepted )
287- {
288- return $ val === $ excepted ;
289- }
290-
291- /**
292- * 不能等于给定值
293- * @param mixed $val
294- * @param mixed $excepted
295- * @return bool
296- */
297- public static function notBe ($ val , $ excepted )
298- {
299- return $ val !== $ excepted ;
300- }
301-
302280 /**
303281 * 最小值检查
304282 * @param int|string|array $val
@@ -337,6 +315,37 @@ public static function length($val, $minLength = 0, $maxLength = null)
337315 return self ::size ($ val , $ minLength , $ maxLength );
338316 }
339317
318+ /**
319+ * 固定的长度
320+ * @param mixed $val
321+ * @param int $size
322+ * @return bool
323+ */
324+ public static function fixedLength ($ val , $ size )
325+ {
326+ return self ::fixedSize ($ val , $ size );
327+ }
328+
329+ /**
330+ * @param mixed $val
331+ * @param int $size
332+ * @return bool
333+ */
334+ public static function fixedSize ($ val , $ size )
335+ {
336+ if (!\is_int ($ val )) {
337+ if (\is_string ($ val )) {
338+ $ val = Helper::strlen (trim ($ val ));
339+ } elseif (\is_array ($ val )) {
340+ $ val = \count ($ val );
341+ } else {
342+ return false ;
343+ }
344+ }
345+
346+ return $ val === (int )$ size ;
347+ }
348+
340349 /*******************************************************************************
341350 * custom validators
342351 ******************************************************************************/
@@ -650,13 +659,25 @@ public static function notIn($val, $dict)
650659 }
651660
652661 /**
653- * @param mixed $val
654- * @param mixed $compareVal
662+ * 必须是等于给定值
663+ * @param mixed $val
664+ * @param mixed $excepted
655665 * @return bool
656666 */
657- public static function compare ($ val , $ compareVal )
667+ public static function mustBe ($ val , $ excepted )
658668 {
659- return $ val === $ compareVal ;
669+ return $ val === $ excepted ;
670+ }
671+
672+ /**
673+ * 不能等于给定值
674+ * @param mixed $val
675+ * @param mixed $excepted
676+ * @return bool
677+ */
678+ public static function notBe ($ val , $ excepted )
679+ {
680+ return $ val !== $ excepted ;
660681 }
661682
662683 /*******************************************************************************
0 commit comments