Prasad Bolla's SharePoint Blog

Click Here to go through the Interesting posts within my Blog.

Click Here to go through the new posts in my blog.

Monday, December 05, 2011

Sample Code URL Validation


<html>
<head>
<title>Website URL Validation with JavaScript</title>

<script language="JavaScript">
<!--
function url_validate(userUrl)
{

var regUrl = /^(((ht|f){1}(tp:[/][/]){1})|((www.){1}))[-a-zA-Z0-9@:%_\+.~#?&//=]+$/;

if(regUrl.test(userUrl) == false)
{

alert('Invalid Url')

}
else
{

alert('Valid Url');

}
}
-->
</script>

<style type="text/css">
<!--
body {
background:#CCCCFF;
}

div {
width: 100%;
text-align: center;
margin-top:150px;
}

span {
color: #000099;
font: 8pt verdana;
font-weight:bold;
text-decoration:none;
}

input {
color: #000000;
background: #F8F8F8;
border: 1px solid #353535;
width:250px;
font: 8pt verdana;
font-weight:normal;
text-decoration:none;
margin-top:5px;
}
-->
</style>
</head>
<body>

<div>
<span id="status">Please enter a valid Website URL.</span><br>
<input type="text" name="website_url" onkeyup="url_validate(this.value);">
</div>

</body>
</html>

No comments:

Post a Comment