jquery验证 - 验证数组长度

时间:2018-02-22 22:59:18

标签: jquery jquery-validate

我需要使用jquery验证插件并检查数组的长度。如果长度超过最大阈值,我需要在textarea控件下面显示一条消息。

使用用户在textarea中输入的值创建数组。

我试着效仿这个例子:https://jqueryvalidation.org/jQuery.validator.addMethod/并开始编写如下所示的方法,

var names = GetNameList(); //returns the names entered in textarea in array format.

jQuery.validator.addMethod("NameCount", function(value, element) {
  return names.length <= 10;
}, "More than 10 names is not allowed");

但是,我想知道,jquery验证插件中是否有更好的方法或内置方法来验证数组的长度?

任何建议都将不胜感激。

0 个答案:

没有答案