Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
0
rated 0 times [  4] [ 4]  / answers: 1 / hits: 39597  / 14 Years ago, fri, april 2, 2010, 12:00:00

All,



I am trying to use JQuery's URL Validator plugin.



http://docs.jquery.com/Plugins/Validation/Methods/url



I have a text box that has a URL. I want to write a function which takes the textbox value, uses the jquery's validator plugin to validate urls and returns true or false.



Something like Ex:



function validateURL(textval)
{
// var valid = get jquery's validate plugin return value
if(valid)
{
return true;
}
return false;
}


I wanted this to be a reusable function..



Thanks


More From » jquery

 Answers
88

The validate() jQuery is made to validate a form itself I believe, not just an individual field.



I think you would be better off using a regex to validate a single textbox if you are not trying to a do a form validation.



Here's an example of a SO question that works.



function validateURL(textval) {
var urlregex = new RegExp(
^(http://www.|https://www.|ftp://www.|www.){1}([0-9A-Za-z]+.));
return urlregex.test(textval);
}


Source: here


[#97174] Wednesday, March 31, 2010, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
hugo

Total Points: 21
Total Questions: 120
Total Answers: 107

Location: Belarus
Member since Tue, Jul 20, 2021
3 Years ago
;