<?xml version="1.0" encoding="UTF-8"?> <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" ><channel><title>Cool Geex &#187; PHP / MySql</title> <atom:link href="http://www.coolgeex.com/category/php-mysql/feed/" rel="self" type="application/rss+xml" /><link>http://www.coolgeex.com</link> <description>Gadget and tech guide for the rest of us</description> <lastBuildDate>Tue, 27 Jul 2010 16:56:51 +0000</lastBuildDate> <generator>http://wordpress.org/?v=2.9.1</generator> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <atom:link rel='hub' href='http://www.coolgeex.com/?pushpress=hub'/> <item><title>PHP Email Address Validator</title><link>http://www.coolgeex.com/php-email-address-validator/</link> <comments>http://www.coolgeex.com/php-email-address-validator/#comments</comments> <pubDate>Tue, 11 Aug 2009 00:40:58 +0000</pubDate> <dc:creator>Cool Geex</dc:creator> <category><![CDATA[PHP / MySql]]></category><guid isPermaLink="false">http://www.coolgeex.com/?p=25</guid> <description><![CDATA[ Few Years ago I wrote an email validator function for sites forms, one that I used until I found email address validator from Google Code.Enjoy the code by clicking the download now button.[PHP]check_text_length($strEmailAddress, 3, 256)) { return false; } // Split it into sections using last instance of &#8220;@&#8221; $intAtSymbol = strrpos($strEmailAddress, &#8216;@&#8217;); if ($intAtSymbol === false) { // No &#8220;@&#8221; [...]]]></description> <content:encoded><![CDATA[<p style="text-align: left;"><img class="size-thumbnail wp-image-26 aligncenter" title="email-validator" src="http://www.coolgeex.com/wp-content/uploads/2009/08/email-validator-150x143.gif" alt="email-validator" width="150" height="143" /></p><p>Few Years ago I wrote an email validator function for sites forms, one that I used until I found email address validator from Google Code.Enjoy the code by clicking the download now button.</p><form style="text-align: left;"> <input onclick="window.location.href='http://www.coolgeex.com/http://www.coolgeex.com/wp-content/uploads/2009/08/EmailAddressValidator.php.zip'" type="button" value="Download Now" /></form><p><span id="more-25"></span></p><p>[PHP]check_text_length($strEmailAddress, 3, 256)) {<br /> return false;<br /> }</p><p>// Split it into sections using last instance of &#8220;@&#8221;<br /> $intAtSymbol = strrpos($strEmailAddress, &#8216;@&#8217;);<br /> if ($intAtSymbol === false) {<br /> // No &#8220;@&#8221; symbol in email.<br /> return false;<br /> }<br /> $arrEmailAddress[0] = substr($strEmailAddress, 0, $intAtSymbol);<br /> $arrEmailAddress[1] = substr($strEmailAddress, $intAtSymbol + 1);</p><p>// Count the &#8220;@&#8221; symbols. Only one is allowed, except where<br /> // contained in quote marks in the local part. Quickest way to<br /> // check this is to remove anything in quotes. We also remove<br /> // characters escaped with backslash, and the backslash<br /> // character.<br /> $arrTempAddress[0] = preg_replace(&#8216;/./&#8217;<br /> ,&#8221;<br /> ,$arrEmailAddress[0]);<br /> $arrTempAddress[0] = preg_replace(&#8216;/&#8221;[^"]+&#8221;/&#8217;<br /> ,&#8221;<br /> ,$arrTempAddress[0]);<br /> $arrTempAddress[1] = $arrEmailAddress[1];<br /> $strTempAddress = $arrTempAddress[0] . $arrTempAddress[1];<br /> // Then check &#8211; should be no &#8220;@&#8221; symbols.<br /> if (strrpos($strTempAddress, &#8216;@&#8217;) !== false) {<br /> // &#8220;@&#8221; symbol found<br /> return false;<br /> }</p><p>// Check local portion<br /> if (!$this-&amp;gt;check_local_portion($arrEmailAddress[0])) {<br /> return false;<br /> }</p><p>// Check domain portion<br /> if (!$this-&amp;gt;check_domain_portion($arrEmailAddress[1])) {<br /> return false;<br /> }</p><p>// If we&#8217;re still here, all checks above passed. Email is valid.<br /> return true;</p><p>}</p><p>/**<br /> * Checks email section before &#8220;@&#8221; symbol for validity<br /> * @param   strLocalPortion     Text to be checked<br /> * @return  True if local portion is valid, false if not<br /> */<br /> protected function check_local_portion($strLocalPortion) {<br /> // Local portion can only be from 1 to 64 characters, inclusive.<br /> // Please note that servers are encouraged to accept longer local<br /> // parts than 64 characters.<br /> if (!$this-&amp;gt;check_text_length($strLocalPortion, 1, 64)) {<br /> return false;<br /> }<br /> // Local portion must be:<br /> // 1) a dot-atom (strings separated by periods)<br /> // 2) a quoted string<br /> // 3) an obsolete format string (combination of the above)<br /> $arrLocalPortion = explode(&#8216;.&#8217;, $strLocalPortion);<br /> for ($i = 0, $max = sizeof($arrLocalPortion); $i &amp;lt; $max; $i++) {                  if (!preg_match(&#8216;.^(&#8216;                                 .    &#8216;([A-Za-z0-9!#$%&amp;amp;'*+/=?^_`{|}~-]&#8216;                                 .    &#8216;[A-Za-z0-9!#$%&amp;amp;'*+/=?^_`{|}~-]{0,63})&#8217;                                 .&#8217;|&#8217;                                 .    &#8216;(&#8220;[^\"]{0,62}&#8221;)&#8217;                                 .&#8217;)$.&#8217;                                 ,$arrLocalPortion[$i])) {                     return false;                 }             }             return true;         }         /**          * Checks email section after &#8220;@&#8221; symbol for validity          * @param   strDomainPortion     Text to be checked          * @return  True if domain portion is valid, false if not          */         protected function check_domain_portion($strDomainPortion) {             // Total domain can only be from 1 to 255 characters, inclusive             if (!$this-&amp;gt;check_text_length($strDomainPortion, 1, 255)) {<br /> return false;<br /> }<br /> // Check if domain is IP, possibly enclosed in square brackets.<br /> if (preg_match(&#8216;/^(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])&#8217;<br /> .&#8217;(.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}$/&#8217;<br /> ,$strDomainPortion) ||<br /> preg_match(&#8216;/^[(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])&#8217;<br /> .&#8217;(.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}]$/&#8217;<br /> ,$strDomainPortion)) {<br /> return true;<br /> } else {<br /> $arrDomainPortion = explode(&#8216;.&#8217;, $strDomainPortion);<br /> if (sizeof($arrDomainPortion) &amp;lt; 2) {<br /> return false; // Not enough parts to domain<br /> }<br /> for ($i = 0, $max = sizeof($arrDomainPortion); $i &amp;lt; $max; $i++) {                     // Each portion must be between 1 and 63 characters, inclusive                     if (!$this-&amp;gt;check_text_length($arrDomainPortion[$i], 1, 63)) {<br /> return false;<br /> }<br /> if (!preg_match(&#8216;/^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|&#8217;<br /> .&#8217;([A-Za-z0-9]+))$/&#8217;, $arrDomainPortion[$i])) {<br /> return false;<br /> }<br /> if ($i == $max &#8211; 1) { // TLD cannot be only numbers<br /> if (strlen(preg_replace(&#8216;/[0-9]/&#8217;, &#8221;, $arrDomainPortion[$i])) &amp;lt;= 0) {<br /> return false;<br /> }<br /> }<br /> }<br /> }<br /> return true;<br /> }</p><p>/**<br /> * Check given text length is between defined bounds<br /> * @param   strText     Text to be checked<br /> * @param   intMinimum  Minimum acceptable length<br /> * @param   intMaximum  Maximum acceptable length<br /> * @return  True if string is within bounds (inclusive), false if not<br /> */<br /> protected function check_text_length($strText, $intMinimum, $intMaximum) {<br /> // Minimum and maximum are both inclusive<br /> $intTextLength = strlen($strText);<br /> if (($intTextLength &amp;lt; $intMinimum) || ($intTextLength &amp;gt; $intMaximum)) {<br /> return false;<br /> } else {<br /> return true;<br /> }<br /> }</p><p>}<br /> [/PHP]</p> ]]></content:encoded> <wfw:commentRss>http://www.coolgeex.com/php-email-address-validator/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
<!-- This site's performance optimized by W3 Total Cache. Dramatically improve the speed and reliability of your blog!

Learn more about our WordPress Plugins: http://www.w3-edge.com/wordpress-plugins/

Minified using apc
Page Caching using apc (user agent is rejected)
Database Caching 27/35 queries in 0.013 seconds using apc

Served from: 10.10.10.43 @ 2010-07-30 00:38:43 -->