如何使用jquery为字段设置最小长度?

我在表单中有4个电子邮件字段,我希望用户在提交按钮时,其所需填写最少1个字段。

这是html:





我该怎么做?

 $('#new_invitation').submit(function(event) { if ($('#invitation_form_recipients input').filter(function() { return $(this).val(); }).length == 0) { // all the fields are empty // show error message here // this blocks the form from submitting event.preventDefault(); } }); 

一种方法:连接四个值,如果它不是空白,那么你肯定其中一个已被填写。

这应该工作: