Wednesday, October 21, 2009

[jQuery] Re: (validate) preclude, deny, disallow or prohibit URLs from submitting

You need to create a new plugin method:

$(function() {
$.validator.addMethod("no_urls",
function(value, element) {
var re = new RegExp("([a-z\d\\-]+\\.)+[a-z]+)", "i"); // or
whatever RegExp you want
var url_found = re.test(value);
return this.optional(element) || (!url_found);
},
"URLs are not allowed."
);
});

Then, in your validate() call, do the following:

// $f is the form
$f.validate({
rules : {
comment : {
required : true,
no_urls : true
}
}
});

On Oct 21, 3:14 am, gdekadt <gdek...@gmail.com> wrote:
> [bump] Anybody out there with any clues or suggestions?
>
> On Oct 15, 11:05 am, gdekadt <gdek...@gmail.com> wrote:
>
> > Hi all sorry - I can't figure this out and I'm a little thick.
>
> > I'm using the great validation plug-in from bassistance and would like
> > to use it to stop a form submitting contents of a *required* comment
> > field when a URL is present in there. [Getting spam links submitted to
> > a contact from]
>
> > I've previously managed to hack the plugin to allow spaces and a
> > leading "+" for phone numbers but this is beyond me as I'm not trying
> > to extend but rather invert the function. ?
>
> > I've been trying for two hours and can neither find anything out there
> > - or hack anything that works.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate