File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed
Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -1708,6 +1708,16 @@ public function format(...$args): self
17081708 return $ this ;
17091709 }
17101710
1711+ /**
1712+ * Returns true if the string is hex color, false otherwise.
1713+ *
1714+ * @return bool Returns TRUE on success or FALSE otherwise.
1715+ */
1716+ public function isHexColor (): bool
1717+ {
1718+ return (bool ) mb_ereg_match ('^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$ ' , $ this ->string );
1719+ }
1720+
17111721 /**
17121722 * Returns true if the string is affirmative, false otherwise.
17131723 *
Original file line number Diff line number Diff line change 752752 $ this ->assertFalse (Strings::create ('90/11/2022 ' )->isDate ());
753753});
754754
755+ test ('test isAffirmative() method ' , function (): void {
756+ $ this ->assertTrue (Strings::create ('true ' )->isAffirmative ());
757+ $ this ->assertTrue (Strings::create ('yes ' )->isAffirmative ());
758+ $ this ->assertTrue (Strings::create ('t ' )->isAffirmative ());
759+ $ this ->assertTrue (Strings::create ('y ' )->isAffirmative ());
760+ $ this ->assertTrue (Strings::create ('ok ' )->isAffirmative ());
761+ $ this ->assertTrue (Strings::create ('okay ' )->isAffirmative ());
762+ });
755763
756764test ('test isLower() method ' , function (): void {
757765 $ this ->assertTrue (Strings::create ('fòôbàřs ' )->isLower ());
768776 $ this ->assertTrue (Strings::create ('19FDE ' )->isHexadecimal ());
769777});
770778
779+ test ('test isHexColor() method ' , function (): void {
780+ $ this ->assertTrue (Strings::create ('#333 ' )->isHexColor ());
781+ $ this ->assertFalse (Strings::create ('#3333 ' )->isHexColor ());
782+ $ this ->assertTrue (Strings::create ('fff ' )->isHexColor ());
783+ $ this ->assertFalse (Strings::create ('fffff ' )->isHexColor ());
784+ });
785+
771786test ('test isPrintable() method ' , function (): void {
772787 $ this ->assertTrue (Strings::create ('fòôbàřs ' )->isPrintable ());
773788 $ this ->assertTrue (Strings::create ('19FDE ' )->isPrintable ());
You can’t perform that action at this time.
0 commit comments