|
-
Feb 14th, 2005, 08:25 AM
#1
Thread Starter
Member
javascript to validate an entry is in URL format.
Hello
I was wondering if anyone could possibly help, im looking to create a javascript function that will validate whether or not a user entry into a text element of form is actually in the correct URL format.
This is my form code at the moment.
<input type="text" size="70" id="inurl" name="inurl" value="">
<input type="button" value="Request URL" id="suburl" onClick="document.Assignment1.updateURL(document.getElementById('inurl').value)">
</form>
Thanks
Last edited by relentless32; Feb 14th, 2005 at 09:11 AM.
-
Feb 14th, 2005, 01:20 PM
#2
Fanatic Member
Re: javascript to validate an entry is in URL format.
I gonna kinda write this on the fly here, without performing much testing so here goes (I'll include complete html)....
Code:
<html><head>
<script language=javascript>
function ValidateOrder(form) {
if(form.inurl.value.match(/^http[s]*\:\/\/[wW]{3}\.+[a-zA-Z0-9]+\.[a-zA-Z]{2,3}.*$|^http[s]*\:\/\/[^w]{3}[a-zA-Z0-9]+\.[a-zA-Z]{2,3}.*$|http[s]*\:\/\/[0-9]{2,3}\.[0-9]{2,3}\.[0-9]{2,3}\.[0-9]{2,3}.*$/) == null)
{alert ("Please enter a valid url."); from.inurl.focus(); return;}
}
</script>
</head><body><form name=form action="test.html">
<input type=text size=70 name=inurl>
<input type=button value="test" onClick="ValidateOrder(this.form)"></form>
That should require either "http://" or "https://" along with either an ipa or url (with or without the "www.").
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|