|
<?php |
|
|
|
/* |
|
* Copyright by SoftCreatR.dev. |
|
* |
|
* License: https://softcreatr.dev/license-terms |
|
* |
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
|
* IN THE SOFTWARE. |
|
* |
|
* The above copyright notice and this disclaimer notice shall be included in all |
|
* copies or substantial portions of the Software. |
|
*/ |
|
|
|
require_once 'ScEmailValidator.php'; |
|
|
|
$emails = [ |
|
'[email protected]', // A basic email address with a valid domain name. |
|
'[email protected]', // A valid email address with numbers in the local part. |
|
'[email protected]', // A valid email address with a period in the local part. |
|
'[email protected]', // A valid email address with a plus sign in the local part. |
|
'[email protected]', // A valid email address with a two-level domain name. |
|
'[email protected]', // A valid email address with a new top-level domain name. |
|
'user@[192.0.2.255]', // A valid email address with an IPv4 address literal as the domain name. |
|
'user@[IPv6::1]', // A valid email address with an IPv6 address literal as the domain name. |
|
'[email protected].', // A valid email address with a trailing dot in the domain name. |
|
'[email protected]', // A valid email address with a subdomain. |
|
'[email protected]', // A valid email address with an IDN. |
|
'[email protected]', // A valid email address with an unquoted IPv4 address as the domain name. |
|
'[email protected]', // A valid email address with a hyphen at the end of the domain name. |
|
'[email protected]', // A valid email address with a hyphen at the beginning of the domain name. |
|
'user@com', // A valid email address with a two-letter top-level domain name. |
|
'user@example.中国', // A valid email address with an IDN containing non-ASCII characters. |
|
'user@[IPv6:2001:db8::1]', // A valid email address with a long-form IPv6 address literal. |
|
'user@[IPv6::2:1]', // A valid email address with a short-form IPv6 address literal. |
|
'[email protected]', // A valid email address with a domain name longer than 255 characters. |
|
'[email protected]', // A valid email address with a subdomain longer than 63 characters. |
|
'user@"quoted\"string"@example.com', // A valid email address with a quoted string containing a double quote. |
|
'user@\'quoted\\\'string\'@example.com', // A valid email address with a quoted string containing a single quote. |
|
'"[email protected]"@example.com', // A valid email address with a quoted string containing an unusual character. |
|
'user@localhost', // A valid email address with the special domain name "localhost". |
|
'user@com.', // A valid email address with a domain name containing a trailing dot. |
|
'[email protected]', // An invalid email address with two consecutive dots in the domain name. |
|
'[email protected]', // An invalid email address with a hyphen at the beginning of the domain name. |
|
'[email protected]', // An invalid email address with a hyphen at the end of the domain name. |
|
'user@exam_ple.com', // An invalid email address with an underscore in the domain name. |
|
'user@exam ple.com' // An invalid email address with a space in the domain name. |
|
]; |
|
|
|
foreach ($emails as $email) { |
|
echo "$email is " . (EmailValidator::validateEmail($email) ? 'valid' : 'invalid') . PHP_EOL; |
|
} |
It is known that the regex is not yet perfect and recognizes as invalid some special cases that are valid according to RFC 2822. A fix is in the works.