AspBucket offers ASP.NET, C#, VB, Jquery, CSS, Ajax, SQL tutorials. It is the best place for programmers to learn

Saturday, 25 June 2016

How to Validate URL without or with http(s) in JavaScript?

In this article I am going to discuss How to validate URL without or with http(s) in JavaScript? Please check below java script code.
Code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>How to Validate URL without or with http(s) in JavaScript?</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$( document ).ready(function() {
  $('#btnValidate').click(function() {
    var txt = $('#txturl').val();
    var re = /(http(s)?:\\)?([\w-]+\.)+[\w-]+[.com|.in|.org]+(\[\?%&=]*)?/
    if (re.test(txt)) {
    alert('Valid URL')
   }
    else {
     alert('Please enter valid URL');
     return false;
    }
  });
});
</script>
</head>
<body>
<div>
 Input URL :<input type="text" id="txturl" />
<input type="button" id="btnValidate" value="Validate" />
</div>
</body>
</html>

Test Cases:
1- aspbucket
Result: Fail

2- aspbucket.com
Result: Pass

3-www.aspbucket.com
ResultPass

4-http://aspbucket.com
Result:Pass

5-http://www.aspbucket.com
ResultPass

   1 comment :

  1. Adding in the fun is a single-site progressive that resets at $10,000. And increasingly, the psychological and technical techniques originally constructed for slot machines — together with reward schedules and tracking techniques — have discovered admirers in Silicon Valley. I agree with everyone 메이저사이트 who contributed to the article, which states the RNG is not RNG. truly have} proven over 12 years of enjoying in} land-based slots in the USA that slot machines aren't random, as individuals and others claiming to be experts declare. I study patterns on several of} hundred slot machine plays, enjoying in} every week. When enjoying in} slot machines, truly have} retained patterns over the years.

    ReplyDelete

  • Popular Posts
  • Comments