Steven
Steven

Reputation: 25314

How to add a customized method to determine the number of words in an input box with Jquery form validation plugin?

I am developing a website which is similar to stackoverflow.com. A poster is required to enter 1 to 3 tags for his problem or task.If a tag has more than one word, then - is used to combine multiple words into single-words, space is used to separate tags. I use Jquery form validation plugin to validate the form. I need to add a customized method to validate the tag input box.

   $.validator.addMethod("tagcheck", function(value, element) { 
 return //To determine the value contains no more than 3 words.

}, "Please input at most 3 tags.");

How to write the customized method?

Upvotes: 0

Views: 173

Answers (1)

Bjorn
Bjorn

Reputation: 71930

 $.validator.addMethod("tagcheck", function(value, element) { 
 return value && value.split(" ").length < 4;

}, "Please input at most 3 tags.");

Upvotes: 1

Related Questions