etahchen
03-02-2009, 06:25 AM
ahh! please help me. i'm sure this is easy is you know javascript already. thanks.
this is supposed to validate an URL input. so it checks first for "http://" i put four of //// cause aren't they special characters that i have to escape? and it i check for letters and numbers. then it has to end with a "." and then at least three letters.
<html>
<head>
<SCRIPT language="JavaScript">
function check_it()
{
to_match=/http://[a-zA-Z0-9-].{1,3}/
var okay= document.s1.t1.value;
if (to_match.test(okay))
{
window.alert("okay great URL!");
return true;
}
else
{
window.alert("NO! try again!");
return false;
}
</SCRIPT>
</HEAD>
<body>
<FORM name="s1" onSubmit="return check_it()">
<INPUT type="text" name="t1">
<INPUT type="submit" action="#">
</FORM>
</body>
</HTML>
this is supposed to validate an URL input. so it checks first for "http://" i put four of //// cause aren't they special characters that i have to escape? and it i check for letters and numbers. then it has to end with a "." and then at least three letters.
<html>
<head>
<SCRIPT language="JavaScript">
function check_it()
{
to_match=/http://[a-zA-Z0-9-].{1,3}/
var okay= document.s1.t1.value;
if (to_match.test(okay))
{
window.alert("okay great URL!");
return true;
}
else
{
window.alert("NO! try again!");
return false;
}
</SCRIPT>
</HEAD>
<body>
<FORM name="s1" onSubmit="return check_it()">
<INPUT type="text" name="t1">
<INPUT type="submit" action="#">
</FORM>
</body>
</HTML>