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