I have got the following code written for validating an email address. The function StrChkInv($em) is incomplete it will check for invalid characters and return true if not found or false if found.
[code=php]<?PHP
function StrChkInv($em)
{}
function ChkEm($em)
{
if(strpbrk($em, ‘@’))
{
return true;
}
}
/*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’);
/*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);
/*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;
}
}
}
/* Return false if none of substrings match the listed domain names*/
if( $flag == false)
{
return false;
}
};
As you can see I have created three array containing TLDs and one more for the .museum would be created shortly. I know this seems foolish but the fact is I can’t use getmxrr or checkdnsrr because they won’t work on Windows servers.
Please suggest a shorter method perhaps using OOPs or by suggesting a solution to use any existing forms of getmxrr or checkdnsrr on Windows as well as UNIX servers. Also can use tell me of an existing open-source PHP class that checks for invalid characters and which invalid characters should be included while validating email ID’s and which while validating names, text-messages.