Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery URL Validator

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

like image 732
Jake Avatar asked Apr 02 '10 19:04

Jake


People also ask

What is jQuery validator?

Validation in JQuery: Using JQuery, a form is validated on the client-side before it is submitted to the server, hence saves the time and reduce the load on the server. Form Validation means to validate or check whether all the values are filled correctly or not.

How do you check if jQuery validate is working?

fn , so simply check whether it exists or not; if (typeof jQuery. fn. validationPlugin === "function") { // It's loaded } else { // It's not. }

Why jQuery validation is not working?

Your answer The "$(...). validate is not a function" jQuery error occurs when the jQuery validation plugin is not loaded or the jQuery-related scripts are loaded in an incorrect order. The validation plugin should be loaded after the jQuery library.


1 Answers

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

like image 125
Gabe Avatar answered Oct 18 '22 20:10

Gabe