Norman
Norman

Reputation: 6365

Why is my regex allowing more than 1

My url validation regex is allowing more than 1 . when the www rule next to it works fine. Can u see why and how to solve it? And feel free to comment on my regex

function isurl($this_url)
{
        if(preg_match("/^((http|https):\/{2})+([w]{3})+([\.]{1})+([a-zA-Z0-9-]+)+([\.]{1})+((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 = "http://www..domain.com";

if (isurl($this_url)) 
{echo "Success";} 
else 
{echo "Fail";}

Upvotes: 0

Views: 57

Answers (3)

John Woo
John Woo

Reputation: 263843

remove the + in this ([\.]{1})+, + mean one or more. try this

([\.]{1})

Upvotes: 1

Sébastien Renauld
Sébastien Renauld

Reputation: 19672

([\.]{1})+ evaluates as (.){1 or more times}. On regular expressions, + is NOT a concatenation.

Upvotes: 4

Petr Peller
Petr Peller

Reputation: 8846

"([.]{1})+"

Plus sign means "once or more times".

Upvotes: 4

Related Questions