hackerkts Posted June 22, 2006 Share Posted June 22, 2006 Here's the class:[code]<?PHP/*This program is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2 of the License, or(at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA*/class ValidateEmail{ function InvChrDM($em) { $flag = true; for( $i = 0; $i < strlen($em); $i++) { $cLet = substr($em, $i, 1); if( ctype_alnum($cLet) or $cLet == '-' or $cLet == '.' ) { $flag = TRUE; } else { $flag = FALSE; break; } } return $flag; } function InvChrEM($em) { $flag = true; for( $i = 0; $i < strlen($em); $i++) { $cLet = substr($em, $i, 1); if( ctype_alnum($cLet) or $cLet == '_' or $cLet == '-' or $cLet == '.' ) { $flag = TRUE; } else { $flag = FALSE; break; } } return $flag; } /* Checks for blank fields that contain only whitespace or nothing*/ function ChkBlnk($em) { /*Checks for ONLY whitespace fields ctype_graph checks for printable characters ctype_space chcks for whitespace like space tab etc.*/ if(!ctype_graph($em) and ctype_space($em)) { return false; } /*Checks for blank fields*/ else if($em == "") { return false; } else { return true; } } /* The following function checks for the @ character in the*/ function ChkEm($em) { if(strpbrk($em, '@')) { if(substr_count($em, '@') > 1) { return false; } else { return true; } } else { return false; } } /*Checks for validity of domain name*/ function ChkDom($em) { /* Three character domain names */ $dm1 = array( '.ac', '.ad', '.ae', '.af', '.ag', '.ai', '.al', '.am', '.an', '.ao', '.aq', '.ar', '.as', '.at', '.au', '.aw', '.az', '.ba', '.bb', '.bd', '.be', '.bf', '.bg', '.bh', '.bi', '.bj', '.bm', '.bn', '.bo', '.br', '.bs', '.bt', '.bv', '.bw', '.by', '.bz', '.ca', '.cc', '.cd', '.cf', '.cg', '.ch', '.ci', '.ck', '.cl', '.cm', '.cn', '.co', '.cr', '.cu', '.cv', '.cx', '.cy', '.cz', '.de', '.dj', '.dk', '.dm', '.do', '.dz', '.ec', '.ee', '.eg', '.eh', '.er', '.es', '.et', '.fi', '.fj', '.fk', '.fm', '.fo', '.fr', '.ga', '.gd', '.ge', '.gf', '.gg', '.gh', '.gi', '.gl', '.gm', '.gn', '.gp', '.gq', '.gr', '.gs', '.gt', '.gu', '.gw', '.gy', '.hk', '.hm', '.hn', '.hr', '.ht', '.hu', '.id', '.ie', '.il', '.im', '.in', '.io', '.iq', '.ir', '.is', '.it', '.je', '.jm', '.jo', '.jp', '.ke', '.kg', '.kh', '.ki', '.km', '.kn', '.kp', '.kr', '.kw', '.ky', '.kz', '.la', '.lb', '.lc', '.li', '.lk', '.lr', '.ls', '.lt', '.lu', '.lv', '.ly', '.ma', '.mc', '.md', '.mg', '.mh', '.mk', '.ml', '.mm', '.mn', '.mo', '.mp', '.mq', '.mr', '.ms', '.mt', '.mu', '.mv', '.mw', '.mx', '.my', '.mz', '.na', '.nc', '.ne', '.nf', '.ng', '.ni', '.nl', '.no', '.np', '.nr', '.nu', '.nz', '.om', '.pa', '.pe', '.pf', '.pg', '.ph', '.pk', '.pl', '.pm', '.pn', '.pr', '.ps', '.pt', '.pw', '.py', '.qa', '.re', '.ro', '.ru', '.rw', '.sa', '.sb', '.sc', '.sd', '.se', '.sg', '.sh', '.si', '.sj', '.sk', '.sl', '.sm', '.sn', '.so', '.sr', '.st', '.sv', '.sy', '.sz', '.tc', '.td', '.tf', '.tg', '.th', '.tj', '.tk', '.tm', '.tn', '.to', '.tp', '.tr', '.tt', '.tv', '.tw', '.tz', '.ua', '.ug', '.uk', '.um', '.us', '.uy', '.uz', '.va', '.vc', '.ve', '.vg', '.vi', '.vn', '.vu', '.wf', '.ws', '.ye', '.yt', '.yu', '.za', '.zm', '.zw' ); /* Four character domain names */ $dm2 = array( '.biz','.com','.edu','.gov','.int','.mil','.net', 'org', '.pro' ); /*Five character domain names */ $dm3 = array('aero','.coop','.info','.name'); /* Solitary seven-letter domain*/ $dm7 = '.museum'; /*Finds string length and substrings */ $len = strlen($em); $sub3 = substr($em,$len-3, $len); $sub4 = substr($em,$len-4, $len); $sub5 = substr($em,$len-5, $len); $sub7 = substr($em,$len-7, $len); /*Searches if the any of substrings match the listed domain suffixes*/ $flag = false; /* Searches if the three letter substring is valid*/ if( $flag != true ) { for($i = 0; $i < count($dm1); $i++) { if($sub3 == $dm1[$i]) { return true; $flag = true; break; } } } /* Searches if the four letter substring is valid*/ if( $flag != true ) { for($j = 0; $j < count($dm2); $j++) { if($sub4 == $dm2[$j]) { return true; $flag = true; break; } } } /* Searches if the five letter substring is valid*/ if( $flag != true ) { for($k = 0; $k < count($dm3); $k++) { if( $sub5 == $dm3[$k]) { return true; $flag = true; break; } } } /* Searches for seven letter .museum domain*/ if( $flag != true ) { for($l = 0; $l < count($dm7); $l++) { if( $sub7 == $dm7) { return true; $flag = true; break; } } } /* Return false if none of substrings match the listed domain names*/ if( $flag == false) { return false; } } /*Returns the string that comes after the @ character*/ function SpltEmID($em,$what) { $dmn = strpbrk($em, '@'); $dmn = explode('@',$dmn); if($what == 'domain') { return $dmn[0]; } else if($what == 'email') { return $dmn[1]; } else { return FALSE; } } }; function IsValid($eml){ $dm = ValidateEmail::SpltEmID($eml,'email'); $em = ValidateEmail::SpltEmID($eml,'domain'); $tmp1 = ValidateEmail::ChkBlnk($eml); $tmp2 = ValidateEmail::ChkEm($eml); $tmp3 = ValidateEmail::ChkDom($dm); $tmp4 = ValidateEmail::InvChrDM($dm); $tmp5 = ValidateEmail::InvChrEM($em); while(1) { if(!$tmp1) { return '1'; break; } elseif(!$tmp2) { return '2'; break; } elseif(!$tmp3) { return '3'; break; } elseif(!$tmp4) { return '4'; break; } elseif(!$tmp5) { return '5'; break; } else { return '0'; break; } } /*The function returns the following integers for invalid error types * 1 if blank field * 2 if @ char not found * 3 if email on invalid TLD * 4 if invalid characters are found in domain name * 5 if invalid characters are found in email * 0 if the email is valid NOTE : the values returned are in strings and are *NOT* Boolean */ } /*Zip Files Classes*/ /* http://www.phpclasses.org/browse/package/945.html */ /* Send HTML pages */ /* http://www.phpguru.org/static/mime.mail.html */ /* http://phpmailer.sourceforge.net */ /* SQL Courses */ /* http://www.sqlcourse.com/ */ /* http://www.w3schools.com/sql/ */ /* http://www.oreillynet.com/pub/ct/19 */ ?>[/code]How do you use that class ? I keep getting error.Btw.. Is there any tutorial on class ?Any help will be appreciate, thanks alot. Quote Link to comment Share on other sites More sharing options...
trq Posted June 22, 2006 Share Posted June 22, 2006 Try the [a href=\"http://php.net/oop\" target=\"_blank\"]manual[/a]. Quote Link to comment Share on other sites More sharing options...
hackerkts Posted June 22, 2006 Author Share Posted June 22, 2006 Thanks for the manual, now I understand more about class.Btw.. Can someone help me check that class ?I think there's some problem with IsValid($eml)Thanks again. Quote Link to comment Share on other sites More sharing options...
hackerkts Posted June 23, 2006 Author Share Posted June 23, 2006 Bump..Sorry for the bump, anyone has the idea to use this class ? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.