Top Menu

How to validate url in java script

How to validate url in java script
url validation in java scrip

How to validate url in java script

This function can be used for validating url 
function isURL(s) {
var regexp = /http://[A-Za-z0-9.-]{3,}.[A-Za-z]{3}/;
return regexp.test(s);
}
 
 
<html>
<head>
</head>
<script language="javascript">
function isURL(s) {
var regexp = /http://[A-Za-z0-9.-]{3,}.[A-Za-z]{3}/;
alert(regexp.test(s));
}
</script>
<body>
<form>
<input type="text" name="url" size="20" id="url"/>
<input type="button" value="Validate" 
 onClick="javascript:isURL(document.getElementById('url').value);"/>
</form>
</body>
</html>

About The Author

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Close