[ create a new paste ] login | about

Link: http://codepad.org/7Cizzg1H    [ raw code | output | fork ]

PHP, pasted on Sep 2:
<?php
$valid = array(
  'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@letters-in-local.org',
  '01234567890@numbers-in-local.net',
  '&\'*+-./=?^_{}~@other-valid-characters-in-local.net',
  'mixed-1234-in-{+^}-local@sld.net',
  'a@single-character-in-local.org',
  '"quoted"@sld.com',
  '"\e\s\c\a\p\e\d"@sld.com',
  '"quoted-at-sign@sld.org"@sld.com',
  '"escaped\"quote"@sld.com',
  '"back\slash"@sld.com',
  'one-character-third-level@a.example.com',
  'single-character-in-sld@x.org',
  'local@dash-in-sld.com',
  'letters-in-sld@123.com',
  'one-letter-sld@x.org',
  'uncommon-tld@sld.museum',
  'uncommon-tld@sld.travel',
  'uncommon-tld@sld.mobi',
  'country-code-tld@sld.uk',
  'country-code-tld@sld.rw',
  'local@sld.newTLD',
  'punycode-numbers-in-tld@sld.xn--3e0b707e',
  'the-total-length@of-an-entire-address-cannot-be-longer-than-two-hundred-and-fifty-four-characters-and-this-address-is-254-characters-exactly-so-it-should-be-valid-and-im-going-to-add-some-more-words-here-to-increase-the-lenght-blah-blah-blah-blah-bla.org',
  'local@sub.domains.com',
  'bracketed-IP-instead-of-domain@[127.0.0.1]',
);

$invalid = array(
  '@missing-local.org',
  '! #$%`|@invalid-characters-in-local.org',
  '(),:;`|@more-invalid-characters-in-local.org',
  '<>@[]\`|@even-more-invalid-characters-in-local.org',
  '.local-starts-with-dot@sld.com',
  'local-ends-with-dot.@sld.com',
  'two..consecutive-dots@sld.com',
  'partially."quoted"@sld.com',
  'the-local-part-is-invalid-if-it-is-longer-than-sixty-four-characters@sld.net',
  'missing-sld@.com',
  'sld-starts-with-dashsh@-sld.com',
  'sld-ends-with-dash@sld-.com',
  'invalid-characters-in-sld@! "#$%(),/;<>_[]`|.org',
  'missing-dot-before-tld@com',
  'missing-tld@sld.',
  '',
  'the-total-length@of-an-entire-address-cannot-be-longer-than-two-hundred-and-fifty-four-characters-and-this-address-is-255-characters-exactly-so-it-should-be-invalid-and-im-going-to-add-some-more-words-here-to-increase-the-lenght-blah-blah-blah-blah-bl.org',
  'missing-at-sign.net',
  'unbracketed-IP@127.0.0.1',
  'invalid-ip@127.0.0.1.26',
  'another-invalid-ip@127.0.0.256',
  'IP-and-port@127.0.0.1:25',
);

$pattern = '#^[^\.][\w-\.]{1,64}@([\w-\.]*)(\.\w{2,6})$#i';

print_r(preg_grep($pattern, $valid));
print_r(preg_grep($pattern, $invalid));


Output:
Array
(
    [0] => abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@letters-in-local.org
    [1] => 01234567890@numbers-in-local.net
    [10] => one-character-third-level@a.example.com
    [11] => single-character-in-sld@x.org
    [12] => local@dash-in-sld.com
    [13] => letters-in-sld@123.com
    [14] => one-letter-sld@x.org
    [15] => uncommon-tld@sld.museum
    [16] => uncommon-tld@sld.travel
    [17] => uncommon-tld@sld.mobi
    [18] => country-code-tld@sld.uk
    [19] => country-code-tld@sld.rw
    [20] => local@sld.newTLD
    [22] => the-total-length@of-an-entire-address-cannot-be-longer-than-two-hundred-and-fifty-four-characters-and-this-address-is-254-characters-exactly-so-it-should-be-valid-and-im-going-to-add-some-more-words-here-to-increase-the-lenght-blah-blah-blah-blah-bla.org
    [23] => local@sub.domains.com
)
Array
(
    [5] => local-ends-with-dot.@sld.com
    [6] => two..consecutive-dots@sld.com
    [9] => missing-sld@.com
    [10] => sld-starts-with-dashsh@-sld.com
    [11] => sld-ends-with-dash@sld-.com
    [16] => the-total-length@of-an-entire-address-cannot-be-longer-than-two-hundred-and-fifty-four-characters-and-this-address-is-255-characters-exactly-so-it-should-be-invalid-and-im-going-to-add-some-more-words-here-to-increase-the-lenght-blah-blah-blah-blah-bl.org
    [19] => invalid-ip@127.0.0.1.26
    [20] => another-invalid-ip@127.0.0.256
)


Create a new paste based on this one


Comments: