note 52458 added to function.eregi

From: Date: Mon, 02 May 2005 15:09:10 +0000
Subject: note 52458 added to function.eregi
Groups: php.notes 
Request: Send a blank email to php-notes+get-88863@lists.php.net to get a copy of this message
<?php // Completely update for match RFC 2822 and RFC 1035 // http://www.faqs.org/rfcs/rfc2822.html // http://www.faqs.org/rfcs/rfc1035.html // Example results: $email[] = 'foo@example.com'; // matched $email[] = 'foo.bar@example.co.uk'; // matched $email[] = 'foo_bar@example.com'; // matched $email[] = '_foo_bar@example.com'; // matched $email[] = 'foo@example.example'; // matched $email[] = '%#a+f.*&654_-._@ee.xx'; // matched $email[] = 'foo@abc-123.xx'; // matched $email[] = 'a@a.a.a.a.aa'; // matched $email[] = 'a@a9.aa'; // matched $email[] = 'a!b#c$d%e^f&g*h\'i+j-k{l|m}n_/@op.qr'; //matched $email[] = ''; //separator $email[] = 'foo@-example.com'; // not matched $email[] = 'foo@example-.com'; // not matched $email[] = '%#af.*&@a%#b.xx'; // not matched $email[] = 'a@a.99.00.a.aa'; // not matched $email[] = '_-._@-.--'; // not matched $email[] = 'any..thing@bla.bla'; // not matched $email[] = '@.'; // not matched $email[] = '@.com'; // not matched $email[] = '@exam@exam.com'; // not matched $email[] = ' @ .com'; // not matched $email[] = '.bar@example.com'; // not matched $email[] = 'foo.@example.com'; // not matched $email[] = 'foo@example.x'; // not matched $atom = '[-a-z0-9!#$%&\'*+/=?^_`{|}~]'; // allowed characters for part before "at" character $domain = '([a-z]([-a-z0-9]*[a-z0-9]+)?)'; // allowed characters for part after "at" character $regex = '^' . $atom . '+' . // One or more atom characters. '(\.' . $atom . '+)*'. // Followed by zero or more dot separated sets of one or more atom characters. '@'. // Followed by an "at" character. '(' . $domain . '{1,63}\.)+'. // Followed by one or max 63 domain characters (dot separated). $domain . '{2,63}'. // Must be followed by one set consisting a period of two '$'; // or max 63 domain characters. foreach ($email as $example) { if (strlen($example) == 0): echo '&nbsp;<br>'; else: if (eregi($regex, $example)): echo $example . ' matched<br>'; else: echo '<strong>'. $example . ' not matched</strong><br>'; endif; endif; } ?> ---- Manual Page -- http://www.php.net/manual/en/function.eregi.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+52458 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52458&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52458&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52458&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52458&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52458&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+52458&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#88863) next »