Validate URL starts with http: in javascript

Regular expression for validating url that starts with http: in JavaScript such as

          <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");  
              window.alert("URL is  valid");  
        <p>Enter your url address then press Enter.</p>  
        <form action="">  
          <input name="txturl" onchange="URLValidation(this);">  

Author: Pavan

I am developer have good knowledge of ver 05,08,10 and good hand in sql server.Proficient in Object Oriented Programming and javascript, jQuery. Achievements - Integrate Spotfire, appnexus API 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.