@@ -215,7 +215,7 @@ public function phone(): bool
215
215
* @return bool
216
216
* @throws ErrorException
217
217
*/
218
- public function zip (int $ arg1 , int $ arg2 = null ): bool
218
+ public function zip (int $ arg1 , ? int $ arg2 = null ): bool
219
219
{
220
220
if (is_null ($ this ->getStr )) {
221
221
return false ;
@@ -290,6 +290,37 @@ public function isBool(): bool
290
290
return (is_bool ($ this ->value ));
291
291
}
292
292
293
+ /**
294
+ * Is a valid json string
295
+ * @return bool
296
+ */
297
+ public function isJson (): bool
298
+ {
299
+ json_decode ($ this ->value );
300
+ return json_last_error () === JSON_ERROR_NONE ;
301
+ }
302
+
303
+ /**
304
+ * Validate a string as html, check that it contains doctype, html, head and body
305
+ * @return bool
306
+ */
307
+ public function isFullHtml (): bool
308
+ {
309
+ libxml_use_internal_errors (true );
310
+ $ dom = new \DOMDocument ();
311
+ if (!is_string ($ this ->value ) || !$ dom ->loadHTML ($ this ->value , LIBXML_NOERROR | LIBXML_NOWARNING )) {
312
+ return false ; // Invalid HTML syntax
313
+ }
314
+ if (!$ dom ->doctype || strtolower ($ dom ->doctype ->name ) !== "html " ) {
315
+ return false ;
316
+ }
317
+ $ htmlTag = $ dom ->getElementsByTagName ("html " )->length > 0 ;
318
+ $ headTag = $ dom ->getElementsByTagName ("head " )->length > 0 ;
319
+ $ bodyTag = $ dom ->getElementsByTagName ("body " )->length > 0 ;
320
+ return $ htmlTag && $ headTag && $ bodyTag ;
321
+ }
322
+
323
+
293
324
/**
294
325
* Check if the value itself can be Interpreted as a bool value
295
326
* E.g. If value === ([on, off], [yes, no], [1, 0] or [true, false])
@@ -430,7 +461,7 @@ public function max(float $int): bool
430
461
* @param int|null $arg2 end length
431
462
* @return bool
432
463
*/
433
- public function length (int $ arg1 , int $ arg2 = null ): bool
464
+ public function length (int $ arg1 , ? int $ arg2 = null ): bool
434
465
{
435
466
if ($ this ->length >= $ arg1 && (($ arg2 === null ) || $ this ->length <= $ arg2 )) {
436
467
return true ;
@@ -636,7 +667,7 @@ public function age(int $arg1): bool
636
667
$ dateTime = new DateTime ($ this ->value );
637
668
$ birth = (int )$ dateTime ->format ("Y " );
638
669
$ age = ($ now - $ birth );
639
- return ($ age < = $ arg1 );
670
+ return ($ age > = $ arg1 );
640
671
}
641
672
642
673
/**
0 commit comments