Click to See Complete Forum and Search --> : Stop multiple URL entry


edatz
04-01-2010, 12:10 PM
Hi, little question.

I have an input field to type in a URL ro a website.

The user has to type http://etc etc
I've put a maximum of 50 allowable characters on it.

But someone (or a bot) could enter more than one http:// on short URLs

How would I stop more than one URL being entered?

I.E. it counts the number of http://'s and if more than one prints out a message.

Does that make sense?

apeg
04-01-2010, 02:08 PM
sorry... i was in the wrong forum subcategory

i think "strtok()" can do what you need, but I'm no Perl expert.

Nedals
04-01-2010, 07:31 PM
Something like this maybe

my $str = 'http://domian1.comhttp://domain2.com';
$str =~ s!^(http://.+?)http://.+$!$1!;
print "$str\n";

edatz
04-02-2010, 03:13 AM
Thanks Nedals, that will do the trick. Great :D

No worries apeg - happens :)

Just thought Nedals, this works in a straight line and if I have a space in-between the URLs. I tried pasting in a list of them and they all printed (on the actual it would stop at 50 characters).

Is there a way of stopping that?

sorry, I should have considered that in the first place as well

edatz
04-02-2010, 10:01 AM
Hi again, actually the code works if a list is pasted into my forum program. I did about 20 urls, each on a seperate line and only one was posted - the first one.

So there's no problem on that (the original code did allow it).

In my script I only use the one line
$str =~ s!^(http://.+?)http://.+$!$1!;
and it works fine. :)

Thanks again Nedals.