albertcolom/assert-email
Composer 安装命令:
composer require albertcolom/assert-email
包简介
PHP library check email (RFC 2822, DNS, Temporal Mail, Allowed Domains)
关键字:
README 文档
README
PHP >= 5.4
PHP library to check email inspired in webmozart/assert
Installation
composer require albertcolom/assert-email
Example usage
use albertcolom\Assert\AssertEmail; class User { //... public function setEmail(string $email) { AssertEmail::valid($email); } }
$user = new User; $user->setEmail('foo@domain.com'); // true $user->setEmail('foo@domain'); // InvalidArgumentException: Invalid email "foo@domain"
Assertions
Valid
Check email valid RFC 2822
valid($email, $message = '') AssertEmail::valid('foo@domain.com'); // true AssertEmail::valid('foo@domain'); // InvalidArgumentException: Invalid email "foo@domain" AssertEmail::valid('foo@domain', 'Custom message %s'); // InvalidArgumentException: Custom message "foo@domain"
Temporal mail
Check temporary emails, it provides a built-in database of 2000+ domains
temporalMail($email, $message = '')` AssertEmail::temporalMail('foo@domain.com'); // true AssertEmail::temporalMail('foo@yopmail.com'); // InvalidArgumentException: Temporal email is not allowed "foo@yopmail.com" AssertEmail::temporalMail('foo@yopmail.com', 'Custom message %s'); // InvalidArgumentException: Custom message "foo@yopmail.com"
DNS
Check DNS MX registry
dns($email, $message = '') AssertEmail::dns('foo@domain.com'); // true AssertEmail::dns('foo@domain.000'); // InvalidArgumentException: Incorrect domain name "domain.000" AssertEmail::dns('foo@domain.000', 'Custom message %s'); // InvalidArgumentException: Custom message "domain.000"
Domains Allowed
Check if domain allowed list
domainsAllowed($email, array $domains, $message = '') $allowed = ['mysite.com', 'somedomain.xy', 'test.dev']; AssertEmail::domainsAllowed('foo@test.dev', $allowed); // true AssertEmail::domainsAllowed('foo@gmail.com', $allowed); // InvalidArgumentException: Domain is not allowed "foo@gmail.com" AssertEmail::domainsAllowed('foo@gmail.com', $allowed, 'Custom message %s'); // InvalidArgumentException: Custom message "foo@gmail.com"
统计信息
- 总下载量: 68
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-12-04