Use regular expression to validate url
<HTML>
<HEAD>
<SCRIPT language="JavaScript">
function check_it()
{
var theurl=document.f1.t1.value;
var tomatch= /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/
if (tomatch.test(theurl)){
document.write("valid");
return true;
}else{
document.write("invalid");
return false;
}
}
</SCRIPT>
</HEAD>
<BODY>
<FORM name="f1" action="#" onSubmit="return check_it();">
URL:<INPUT type="text" name="t1">
<INPUT type="submit" value="Submit">
</BODY>
</HTML>
Related examples in the same category