Use regular expression to validate the URL : URL : Regular Expressions JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » Regular Expressions » URL »

 

Use regular expression to validate the URL

















<HTML>
<HEAD>
<SCRIPT language="JavaScript">
<!--

function check_it()
{
     var theurl=document.myForm.t1.value;
     var tomatch= /http://[A-Za-z0-9.-]{3,}.[A-Za-z]{3}/

     if (tomatch.test(theurl)){
         window.alert("URL OK.");
         return true;
     }
     else
     {
         window.alert("URL invalid. Try again.");
         return false;
     }
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<FORM name="myForm" action="#" onSubmit="return check_it();">
Enter URL:<BR>
<INPUT type="text" name="t1">
<BR>
<INPUT type="submit" value="Submit">
</BODY>
</HTML>







HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo Regular Expressions
» URL