Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    validating URL input. help!

    ahh! please help me. i'm sure this is easy is you know javascript already. thanks.

    this is supposed to validate an URL input. so it checks first for "http://" i put four of //// cause aren't they special characters that i have to escape? and it i check for letters and numbers. then it has to end with a "." and then at least three letters.

    <html>
    <head>
    <SCRIPT language="JavaScript">

    function check_it()
    {
    to_match=/http://[a-zA-Z0-9-].{1,3}/
    var okay= document.s1.t1.value;
    if (to_match.test(okay))
    {
    window.alert("okay great URL!");
    return true;
    }
    else
    {
    window.alert("NO! try again!");
    return false;
    }

    </SCRIPT>
    </HEAD>
    <body>
    <FORM name="s1" onSubmit="return check_it()">
    <INPUT type="text" name="t1">
    <INPUT type="submit" action="#">
    </FORM>
    </body>
    </HTML>
    Last edited by etahchen; 03-02-2009 at 06:35 AM.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    Try
    Code:
    function check_it()
    {
    to_match=/^http:\/\/[a-zA-Z0-9-]*\.[a-zA-Z]{1,3}$/
    var okay= document.s1.t1.value;
    if (to_match.test(okay))
    {
    window.alert("okay great URL!");
    return true;
    }
    else
    {
    window.alert("NO! try again!");
    return false;
    }
    }
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    thanks

    thanks for that help. it still didn't work. even if i put in a good url, the browser will still say "NO! Try again!".
    but i'm closer to my goal now

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    Quote Originally Posted by etahchen View Post
    thanks for that help. it still didn't work. even if i put in a good url, the browser will still say "NO! Try again!".
    but i'm closer to my goal now
    Could you post some sample 'good urls'?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #5
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

  • #6
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    Try
    Code:
    to_match=/^http:\/\/(www\.){0,1}[a-zA-Z0-9-]*\.[a-zA-Z]{1,3}$/
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #7
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    YYAAAYYY!!!!! thank you! now i'm going to study this and make sure i understand this thoroughly


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •