Validate URL starts with http: in javascript

 
Regular expression for validating url that starts with http: in JavaScript such as https://www.authorcode.com.

   <html>  
      <head>  
          <script type="text/javascript">  
          var reg = /^(ht|f)tp(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)([a-zA-Z0-9\-\.\?\,\'\/\\\+&amp;%\$#_]*)?$/;  
          function URLValidation(url)
          {  
            var OK = reg.exec(url.value);  
            if (!OK)  
              window.alert("URL isn't  valid");  
            else  
              window.alert("URL is  valid");  
          }  
        </script>  
      </head>  
 
      <body>  
        <p>Enter your url address then press Enter.</p>  
        <form action="">  
          <input name="txturl" onchange="URLValidation(this);">  
        </form>  
      </body>  
    </html>

Author: Pavan

I am asp.net developer have good knowledge of Asp.net ver 05,08,10 and good hand in sql server.Proficient in Object Oriented Programming and javascript, jQuery. Achievements - Integrate Spotfire, appnexus API ASP.net with sql server. Hobbies - Blogging ,Games, Movies ,Teaching,Keeping myself update with new technologies

One thought on “Validate URL starts with http: in javascript”

Comments are closed.