@@ -44,7 +44,8 @@ public function alpha_space(?string $value = null): bool
4444 return true ;
4545 }
4646
47- return (bool ) preg_match ('/^[A-Z ]+$/i ' , $ value );
47+ // @see https://regex101.com/r/LhqHPO/1
48+ return (bool ) preg_match ('/\A[A-Z ]+\z/i ' , $ value );
4849 }
4950
5051 /**
@@ -56,7 +57,8 @@ public function alpha_space(?string $value = null): bool
5657 */
5758 public function alpha_dash (?string $ str = null ): bool
5859 {
59- return (bool ) preg_match ('/^[a-z0-9_-]+$/i ' , $ str );
60+ // @see https://regex101.com/r/XfVY3d/1
61+ return (bool ) preg_match ('/\A[a-z0-9_-]+\z/i ' , $ str );
6062 }
6163
6264 /**
@@ -72,7 +74,8 @@ public function alpha_dash(?string $str = null): bool
7274 */
7375 public function alpha_numeric_punct ($ str )
7476 {
75- return (bool ) preg_match ('/^[A-Z0-9 ~!#$%\&\*\-_+=|:.]+$/i ' , $ str );
77+ // @see https://regex101.com/r/6N8dDY/1
78+ return (bool ) preg_match ('/\A[A-Z0-9 ~!#$%\&\*\-_+=|:.]+\z/i ' , $ str );
7679 }
7780
7881 /**
@@ -96,7 +99,8 @@ public function alpha_numeric(?string $str = null): bool
9699 */
97100 public function alpha_numeric_space (?string $ str = null ): bool
98101 {
99- return (bool ) preg_match ('/^[A-Z0-9 ]+$/i ' , $ str );
102+ // @see https://regex101.com/r/0AZDME/1
103+ return (bool ) preg_match ('/\A[A-Z0-9 ]+\z/i ' , $ str );
100104 }
101105
102106 /**
@@ -123,7 +127,8 @@ public function string($str = null): bool
123127 */
124128 public function decimal (?string $ str = null ): bool
125129 {
126- return (bool ) preg_match ('/^[-+]?[0-9]{0,}\.?[0-9]+$/ ' , $ str );
130+ // @see https://regex101.com/r/HULifl/1/
131+ return (bool ) preg_match ('/\A[-+]?[0-9]{0,}\.?[0-9]+\z/ ' , $ str );
127132 }
128133
129134 /**
@@ -147,7 +152,7 @@ public function hex(?string $str = null): bool
147152 */
148153 public function integer (?string $ str = null ): bool
149154 {
150- return (bool ) preg_match ('/^ [\-+]?[0-9]+$ / ' , $ str );
155+ return (bool ) preg_match ('/\A [\-+]?[0-9]+\z / ' , $ str );
151156 }
152157
153158 /**
@@ -181,7 +186,8 @@ public function is_natural_no_zero(?string $str = null): bool
181186 */
182187 public function numeric (?string $ str = null ): bool
183188 {
184- return (bool ) preg_match ('/^[\-+]?[0-9]*\.?[0-9]+$/ ' , $ str );
189+ // @see https://regex101.com/r/bb9wtr/1
190+ return (bool ) preg_match ('/\A[\-+]?[0-9]*\.?[0-9]+\z/ ' , $ str );
185191 }
186192
187193 /**
@@ -253,6 +259,7 @@ public function valid_json(string $str = null): bool
253259 */
254260 public function valid_email (string $ str = null ): bool
255261 {
262+ // @see https://regex101.com/r/wlJG1t/1/
256263 if (function_exists ('idn_to_ascii ' ) && defined ('INTL_IDNA_VARIANT_UTS46 ' ) && preg_match ('#\A([^@]+)@(.+)\z# ' , $ str , $ matches ))
257264 {
258265 $ str = $ matches [1 ] . '@ ' . idn_to_ascii ($ matches [2 ], 0 , INTL_IDNA_VARIANT_UTS46 );
0 commit comments