When I saw this post, I thought to myself that there must be a module that validates that a string has the right form to be a URL (without actually trying to use the string to connect). But I couldn't find one. If you're looking for a "good enough" solution, something like what cianoz proposes would be a start. It depends how nit-picky you're going to be. You might want to make sure there's a protocol ID in the string, and at least one period surrounded by other valid, non-period characters (although http://localhost is valid and won't fit that, so even *that's* not guaranteed). I'm not enough of a regex genius to make that happen (yet), and I don't have the RFC handy. So the following comes with heaps of disclaimers. Hopefully, it will get you started and won't damage your career as a Perl programmer or a human being =)

# since this is messy and we need to use it a bunch of times, let's lo +ad it into a scalar. my $val = "[a-z0-9?]+=\-%"; # there is no way in heck this is correct; + it's a *beginning* though # get input if (is_url($string)) { # do something with it } ... sub is_url { my $input = shift; $input =~ #(?:http(?:s)|ftp)://$val+\.$val+#i; }
HTH

Philosophy can be made out of anything. Or less -- Jerry A. Fodor


In reply to Re: Form validation by arturo
in thread Form validation by Flavia

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.