I’ve been using this regex to validate domain names, and it does really well. I need to add a http://www. or https://www.to it. I’m afraid I’ll mess things up. It currently does not use a http://www.
Also, is there any way to bend this so it’ll reject sub-domains?
So in all it’ll be:
http://www.domain.com -> valid
www.domain.com - > Invalid (Should have the http://www. part)
http://sub.domain.com - > Invalid (Subdomain)
http://www.sub.domain.com -> Invlaid (Subdomain)
I tried doing things with the http://www. part, but ended with error. I’m clueless how to do the sub-domain reject part.
function isurl($this_url)
{
if(preg_match("/^([a-z0-9]([-a-z0-9]*[a-z0-9])?\.)+((a[cdefgilmnoqrstuwxz]|aero|arpa)|(b[abdefghijmnorstvwyz]|biz)|(c[acdfghiklmnorsuvxyz]|cat|com|coop)|d[ejkmoz]|(e[ceghrstu]|edu)|f[ijkmor]|(g[abdefghilmnpqrstuwy]|gov)|h[kmnrtu]|(i[delmnoqrst]|info|int)|(j[emop]|jobs)|k[eghimnprwyz]|l[abcikrstuvy]|(m[acdghklmnopqrstuvwxyz]|mil|mobi|museum)|(n[acefgilopruz]|name|net)|(om|org)|(p[aefghklmnrstwy]|pro)|qa|r[eouw]|s[abcdeghijklmnortvyz]|(t[cdfghjklmnoprtvwz]|travel)|u[agkmsyz]|v[aceginu]|w[fs]|y[etu]|z[amw])$/i", $this_url))
{
return true;
}
}
$this_url = "www.domain.com";
if (isurl($this_url))
{echo "Success";}
else
{echo "Fail";}
try this in htaccess
or use this regx
for perticular