@@ -215,7 +215,7 @@ public function phone(): bool
215215 * @return bool
216216 * @throws ErrorException
217217 */
218- public function zip (int $ arg1 , int $ arg2 = null ): bool
218+ public function zip (int $ arg1 , ? int $ arg2 = null ): bool
219219 {
220220 if (is_null ($ this ->getStr )) {
221221 return false ;
@@ -290,6 +290,37 @@ public function isBool(): bool
290290 return (is_bool ($ this ->value ));
291291 }
292292
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+
293324 /**
294325 * Check if the value itself can be Interpreted as a bool value
295326 * E.g. If value === ([on, off], [yes, no], [1, 0] or [true, false])
@@ -430,7 +461,7 @@ public function max(float $int): bool
430461 * @param int|null $arg2 end length
431462 * @return bool
432463 */
433- public function length (int $ arg1 , int $ arg2 = null ): bool
464+ public function length (int $ arg1 , ? int $ arg2 = null ): bool
434465 {
435466 if ($ this ->length >= $ arg1 && (($ arg2 === null ) || $ this ->length <= $ arg2 )) {
436467 return true ;
@@ -636,7 +667,7 @@ public function age(int $arg1): bool
636667 $ dateTime = new DateTime ($ this ->value );
637668 $ birth = (int )$ dateTime ->format ("Y " );
638669 $ age = ($ now - $ birth );
639- return ($ age < = $ arg1 );
670+ return ($ age > = $ arg1 );
640671 }
641672
642673 /**
0 commit comments