12-08-2007, 10:49 AM
|
#8 (permalink)
|
|
The Frequenter
Join Date: Sep 2007
Posts: 360
Thanks: 24
|
Quote:
Originally Posted by Matt83
I been playing a bit with prototype and thought of giving this a try, im sure it can be improved but anyways here it is, i hope it helps:
HTML Code:
<script src="prototype.js" type="text/javascript"></script>
<script type="text/javascript">
function validateURL (szURL,szTarget,szForm)
{
var bValid = /^(http|https|ftp):\/\/([\w]*)\.([\w]*)\.(com|net|org|biz|info|mobi|us|cc|bz|tv|ws|name|co|me)(\.[a-z]{1,3})?$/.test(szURL);
if (bValid == false) {
$(szTarget).innerHTML = "Please enter a valid URL.";
} else {
$(szTarget).innerHTML = "Valid URL.";
// $(szForm).submit();
}
};
</script>
<h1>Validate URL</h1>
<form id="myForm" action="" method="post">
<p><label>Url:</label><br/>
<input type="text" name="url" value="" id="url" size="40"/></p>
<div id="info"></div>
<p><input type="button" value="Send URL →" onclick="validateURL($('url').value,'info','myForm')"/></p>
</form>
|
There's a cleaner premade solution available.
Please consider FormAssembly's wForms javascript extension.
|
|
|
|