Results 1 to 2 of 2

Thread: Validate url

  1. #1
    Join Date
    Feb 2009
    Posts
    17
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Validate url

    Hello everybody,

    I want to get the javascript code that can validate url.

    Can someone help me?

    Thank you for your kind.

  2. #2
    Join Date
    Jul 2008
    Posts
    40
    Thanks
    1
    Thanked 4 Times in 4 Posts

    Default

    Hi,

    In able to this, you will be needing some event handling inside your page, so that you will be able to trigger specific functions' stated or attached on those events.

    Since we don't have any reference, then i will just have to simulate everything using an onload event with a simple prompt that i will provide on the user when they load the page.

    Here's the code:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
    <html lang="en">
    <head>
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="Content-Script-Type" content="text/javascript">
    <title>http://www.dynamicdrive.com ™</title>
    <script type="text/javascript">
    <!--
    
    onload = ( function() { 
    /* JavaScript Regular Expression DEMO ~
    ********************************
     Valid URL sample :
    ********************************
     - http://www.dynamicdrive.com/
     - http://www.w3.org/
     - http://www.google.com/
    
    ********************************
     Non-Valid URL sample :
    ********************************
     - www.dynamicdrive.com/
     - http://dynamicdrive.com/
     - http://www.dynamicdrive.com/subfolder/
     - http://www.dynamicdrive.com
    _______________________
     ~ The pattern i used on this demo will require the user to enter only the absolute path of the site, excluding any subfolder location.
    *******************************/
       var count;
       var isUserInput;
       var isHome = ( /^(?:http://)w{3}(?:\.)[a-z0-9_\-]+\.?(?=\w+)\w{3}\/$/ );
       do {
          isUserInput = prompt((( count ) ? "Invalid URL address!" : "Enter Address :" ), isUserInput );
          count = (( isHome.test( isUserInput )) ? 0 : 1 ); 
       } while( count !== 0 );
       location.replace( isUserInput );
    
    } );
    
    // ECMA ( JavaScript v1.5 ) -->
    </script>
    </head>
    <body>
    <div id="main"></div>
    </body>
    </html>
    hope it does get what you need...

Bookmarks

Posting Permissions

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