Check and validate url starts with http:// - Javascript String Operation

Javascript examples for String Operation:String URL

Description

Check and validate url starts with http://

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
function checkUR(abc){/*from w  w  w  .j  av  a2  s  .  co  m*/
    string = abc.value
    if(!(/^http:\/\//.test(string))){
        string = "http://" + string;
    }
    abc.value=string
}

      </script> 
   </head> 
   <body> 
      <form> 
         <input type="url" name="someUrl" onkeyup="checkUR(this)"> 
      </form>  
   </body>
</html>

Related Tutorials