o URL starts with a-z, A-Z (e.g. http, ftp...)
o It is then followed by ://
o next we have more letters, numbers and special chars : a-z, A-Z, 0-9, -, _
o there must be at least one "."
o A URL can contain at it's end part the more special characters and this is
why the last part allows for more options such as ?, /, &, %, etc...
you may add/remove chars as needed to your code.
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
function Validate(form) {
var v = new RegExp();
v.compile("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$");
if (!v.test(form["URL"].value)) {
alert("You must supply a valid URL.");
return false;
}
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="MyForm" ACTION="MyFile.php" METHOD="POST" onSubmit="return Validate(this);">
<INPUT TYPE="TEXT" NAME="URL" VALUE="http://">
<INPUT TYPE="SUBMIT" NAME="SUBMIT" VALUE="SUBMIT">
</FORM>
</BODY>
</HTML>