All three problems solved.

On Apr 9, 6:52 pm, dotcomtim <dotcom...@hotmail.com> wrote:
> Solved 1 and 2 just not the third. Anyway to detected duplicates only?
> Everything I found on the net only removes duplicates.
>
> $.validator.addMethod('keywords', function(value, element) {
>         var valid = true;
>         var valid = (value.length > 0);
>         var message = $(element);
>         if (this.optional(element)) {
>                 return true;
>         }
>         var keywords = value.split(',');
>         for (var i in keywords) {
>                 keyword = Trim(keywords[i]);
>                 duplicates = Trim(keywords[i]);
>                 if (!keywords[2]) {
>                         message.parent('div').next('div').empty().append('3 
> required');
>                         var valid = false;
>                 }
>                 else if (keywords[8]) {
>                         message.parent('div').next('div').empty().append('8 
> to many.');
>                         var valid = false;
>                 }
>                 if (keyword.length < 3) {
>                         message.parent('div').next('div').empty().append('3 
> characters
> minimum');
>                         var valid = false;
>                 }
>                 else if (keyword.length > 30) {
>                         message.parent('div').next('div').empty().append('30 
> characters
> maximum');
>                         var valid = false;
>                 }
>                 else if (keyword.match(/\b\w+\b/g).length > 2) {
>                         message.parent('div').next('div').empty().append('2 
> words in
> each');
>                         var valid = false;
>                 }
>                 else {
>                         var words = keyword.split(' ');
>                         for (var i in words) {
>                                 word = Trim(words[i]);
>                                 if (word.length < 3) {
>                                         
> message.parent('div').next('div').empty().append('each word 3
> characters minimum');
>                                         var valid = false;
>                                 }
>                         }
>                 }
>         }
>         return valid;
>
> }, false);
>
> On Apr 9, 10:51 am, dotcomtim <dotcom...@hotmail.com> wrote:
>
> > I am working on a custom filter to check for errors by adding the
> > addMethod() function within the jQuery Validation Plugin. I have
> > success so far with most of it except for the last few items.
>
> > 1) Individual Messages – I like to replace the alert messages to
> > append their own message. I tried several methods according to the
> > plugin except I keep getting this error Warning: No message defined
> > for keywords. I can eliminate this by adding a common error message
> > for keywords except I am looking for individual messages.
>
> > Here is what I have add success with so far.
> > $.validator.addMethod("keywords", function(value, element) {
> >         if (this.optional(element)) {
> >                 return true;
> >         }
> >         var valid = true;
> >         var keywords = value.split(',');
> >         var valid = (value.length > 0);
> >         for (var i in keywords) {
> >                 keyword = Trim(keywords[i]);
> >                 if (keyword.length < 3) {
> >                         //alert('to short '+keyword);
> >                         var valid = false;
> >                 }
> >                 else if (keyword.length > 30) {
> >                         //alert('to long '+keyword);
> >                         var valid = false;
> >                 }
> >                 else if (keyword.match(/\b\w+\b/g).length > 2) {
> >                         //alert('to many words '+keyword);
> >                         var valid = false;
> >                 }
> >                 // else if (duplicates) { }
> >                 // else if (each word greater than 2 characters) {}
> >         }
> >         return valid;
>
> > });
>
> > If I can get help with item 1 I would appreciate it allot. Items 2 and
> > 3 are not important unless someone has done something similar I give
> > suggestions.
>
> > 2) Validate duplicate words – If 2 keywords are the same fire off an
> > error.
>
> > Allow Example: water, waterfront
> > Disallowed Example: waterfront, waterfront
>
> > 3) Validate character length in each word – If an individual word is
> > less than 3 characters fire off an error.
>
> > Allow Example: the waterfront
> > Disallowed Example: a waterfront

Reply via email to