File tree Expand file tree Collapse file tree 1 file changed +14
-10
lines changed
Expand file tree Collapse file tree 1 file changed +14
-10
lines changed Original file line number Diff line number Diff line change @@ -76,19 +76,25 @@ public function getEmail(): string
7676 /**
7777 * Validate if an address is valid.
7878 *
79- * @param string $email The email address to validate.
79+ * Supports formats:
80+ * - john@example.com
81+ * - John Doe <john@example.com>
82+ *
83+ * @param string $address
8084 * @return bool
8185 */
8286 public static function addressValidation (string $ address ): bool
8387 {
84- if (preg_match ('/^(?:[^<]+<[^ >]+>| ' , $ address , $ matches )) {
85- if ( static :: emailValidation ( $ matches [2 ])) {
86- return true ;
87- }
88+ if (preg_match ('/<([^ >]+)>/ ' , $ address , $ matches )) {
89+ $ email = $ matches [1 ];
90+ } else {
91+ $ email = $ address ;
8892 }
89- return false ;
93+
94+ return filter_var ($ email , FILTER_VALIDATE_EMAIL ) !== false ;
9095 }
9196
97+
9298 /**
9399 * Validate if an email address is valid.
94100 *
@@ -97,10 +103,8 @@ public static function addressValidation(string $address): bool
97103 */
98104 public static function emailValidation (string $ email ): bool
99105 {
100- if (filter_var ($ email , FILTER_VALIDATE_EMAIL ) === false ) {
101- return false ;
102- }
103- return true ;
106+ return filter_var ($ email , FILTER_VALIDATE_EMAIL ) !== false ;
107+
104108 }
105109
106110 /**
You can’t perform that action at this time.
0 commit comments