• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..Today-

EmailAddressValidator.phpH A D16-Sep-20217.1 KiB184104

README.mdH A D16-Sep-20212.6 KiB6048

README.md

1Email-Address-Validator
2=======================
3
4This is a fork of [AddedBytes' EmailAddressValidator class](https://code.google.com/p/php-email-address-validation/).
5
6## Changes ##
7Changes include:
8
9- [Composer](https://getcomposer.org/) support
10- Refactored the class to be purely static
11- Opened up methods for checking the "local part" (the bit before the `@`) and the "domain part" (after the `@`)
12to be public methods
13- Additional code style and docblock fixing to properly follow the [PHP-FIG PSR-1](http://www.php-fig.org/psr/psr-1/)
14and [PSR-2](http://www.php-fig.org/psr/psr-2/) documents
15
16Note that this class is still **un-namespaced** - i.e. it's still declared in the global namespace. The `composer.json`
17file is still set up to correctly load it when required, so this shouldn't be a problem in practice - it's just perhaps
18not best-practice.
19
20## Installation ##
21Use [Composer](https://getcomposer.org/):
22```
23php composer.phar require aziraphale/email-address-validator:^2
24```
25
26If you don't want to use Composer (why not?!), just download the `EmailAddressValidator.php` file, save it with your project, and `require` it where needed.
27
28Note that this updated version is **version 2.0.0**. I have kept the original class tagged as **version 1.0.10** (it was the 10th commit to the Google Code svn repository). If you want to use Composer to install the **old** class, simply specify `^1` as the version constraint (which will allow for backwards-compatible changes to be installed, if any get made, while never jumping to my modified class without your direct action):
29```
30php composer.phar require aziraphale/email-address-validator:^1
31```
32
33## Usage ##
34Due to the aforementioned changes, the way of using this class has completely changed. However it has such a small and simple interface that these changes shouldn't be problematic.
35
36As a recap, the **old usage** was like this:
37```php
38$validator = new EmailAddressValidator;
39if ($validator->check_email_address('test@example.org')) {
40    // Email address is technically valid
41}
42```
43
44The **new syntax** is as follows (ensure you have already included Composer's `autoload.php` file!):
45```php
46if (EmailAddressValidator::checkEmailAddress("test@example.org")) {
47    // Email address is technically valid
48}
49```
50
51with a couple of additional methods in case they're helpful:
52```php
53if (EmailAddressValidator::checkLocalPortion("test")) {
54    // "test" is technically a valid string to have before the "@" in an email address
55}
56if (EmailAddressValidator::checkDomainPotion("example.org")) {
57    // "example.org" is technically a valid email address host
58}
59```
60