Skip to content

Commit 60510bc

Browse files
Merge pull request #6 from devMuhammad05/master
Enhance email validation in areCompanyEmails method and update README
2 parents 314ef6b + dc23614 commit 60510bc

File tree

2 files changed

+68
-4
lines changed

2 files changed

+68
-4
lines changed

README.md

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,60 @@
1-
# company-email-validator
2-
A fast and efficient company/work email validator that checks if an email domain belongs to a free email provider.
1+
# **Company Email Validator**
2+
A fast and efficient company/work email validator that checks if an email domain belongs to a free email provider.
3+
4+
[![Packagist Version](https://img.shields.io/packagist/v/devmuhammad/company-email-validator)](https://packagist.org/packages/devmuhammad/company-email-validator) [![Total Downloads](https://img.shields.io/packagist/dt/devmuhammad/company-email-validator)](https://packagist.org/packages/devmuhammad/company-email-validator) [![License](https://img.shields.io/packagist/l/devmuhammad/company-email-validator)](https://packagist.org/packages/devmuhammad/company-email-validator)
5+
6+
---
7+
8+
## **Installation**
9+
Install via Composer:
10+
11+
```bash
12+
composer require devmuhammad/company-email-validator
13+
14+
```
15+
16+
## Usage
17+
18+
#### Validate a single email
19+
20+
```php
21+
22+
use Muhammad\CompanyEmailValidator\EmailValidator;
23+
24+
$validator = new EmailValidator();
25+
$validator->isCompanyEmail("[email protected]"); //true
26+
$validator->isCompanyEmail("[email protected]"); //false
27+
28+
```
29+
30+
#### Validate multiple emails
31+
32+
```php
33+
use Muhammad\CompanyEmailValidator\EmailValidator;
34+
35+
$validator = new EmailValidator();
36+
$validator->areCompanyEmails(["[email protected]", "[email protected]"]);
37+
38+
Output(array):
39+
[
40+
"[email protected]" => true,
41+
"[email protected]" => false
42+
]
43+
```
44+
45+
#### Validate emails against a custom free domain list
46+
47+
```php
48+
use Muhammad\CompanyEmailValidator\EmailValidator;
49+
50+
$email = "[email protected]";
51+
$validator = new EmailValidator(['customfree.com']);
52+
$validator->isCompanyEmail($email); //false
53+
54+
```
55+
56+
## Contribution
57+
58+
Contributions are welcome! Feel free to submit an issue or a pull request.
59+
60+
Check the ``LICENSE`` file for more info.

src/EmailValidator.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,17 @@ public function isCompanyEmail(string $email): bool
4141
public function areCompanyEmails(array $emails): array
4242
{
4343
$results = [];
44-
44+
4545
foreach ($emails as $email) {
46+
if (!$this->validate($email)) {
47+
$results[$email] = false; // Invalid email format
48+
continue;
49+
}
50+
4651
$results[$email] = $this->isCompanyEmail($email);
4752
}
48-
53+
4954
return $results;
5055
}
56+
5157
}

0 commit comments

Comments
 (0)