Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

javascript to validate an entry is in URL format.

Status
Not open for further replies.

HubCapped

Programmer
Feb 8, 2005
4
GB
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
 
Try searching this forum for "regular expression" and "URL".


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
What is considered to be a "valid" url is very subjective. Try plugging one of these regex patterns that fits your needs into something like this:
Code:
if(document.formName.fieldName.value.search(/regularExpressionGoesHere/) > -1){
  alert('Valid URL!');
}

Adam
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top