Saturday 15 May 2010

How to get the number of words in Jquery form validation plugin? -


This tag has input box validation. A poster can combine multiple words into one-word, used to isolate the location tag. I use the Jquery Farm Verification Plugin to validate the form. To validate the tag input box, I need to add an optimized method to this code:

  $ .validator.addMethod ("tagcheck", function (value, element) {return value & Amp; value.split (""). Length & lt; 4;}, "input on maximum 3 tags.");  

But what if there are two places between two adjacent words?

You can use a regular expression for your string:

  $ Validator.addMethod ("tagcheck", function (value, element) {return value & amp; value.split (/ \ S + /). Length & lt; 4;}, "input on maximum 3 tags.");  

\ s + will match one or more white space characters, including space, tabs, form feeds, line feeds.


No comments:

Post a Comment