• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 339
  • Last Modified:

jquery validator textarea min words

Is there any way to use jquery validator to validate the minum of words in the textarea, separated by comma, and tell the custom error message?

For example: 1,2,3 4,5 is 4 words when I split with comma. I need to let them know the minum is 5 words if they submit the form using jquery validator.
0
xiaoyunwu
Asked:
xiaoyunwu
2 Solutions
 
leakim971PluritechnicianCommented:
Using : http://docs.jquery.com/Plugins/Validation/Validator/addMethod

jQuery.validator.addMethod("min5", function(value, element) {
  return this.optional(element) || (value.split(",") >= 5);
}, "Please enter more than 5 words separated by comma");
0
 
sonawanekiranCommented:
In addition to above. You can above min5 function using validate plugin like

$('#Your_form_id').validate({
    rules: {
        your_text_area_id: {
            min5: true;
        }
    }
});
0
 
xiaoyunwuAuthor Commented:
$('#Your_form_id').validate({
    rules: {
        your_text_area_id: {
            min5: true    // there should be no ; here.
        }
    }
});
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now