Formvalidation 验证器跨域

Formvalidation validators cross fields

我花了将近 3 个小时试图理解为什么以下代码块将所有输入验证为数字:

<td class="form-group">
  <input class="form-control" type="text" name="units[]" id="units_0" value="1" size="2" data-fv-notempty="true" data-fv-notempty-message="Valor Requerido" data-fv-regexp="true" data-fv-regexp-regexp="^[0-9]+$" data-fv-regexp-message="Introducir Valor Entero" onchange="calcAmount(this)"/>
</td>

<td class="form-group">
  <input class="form-control" type="text" name="concepts[]" id="concepts_0" size="50" data-fv-notempty="true" data-fv-notempty-message="Introducir Concepto" data-fv-regexp="true" data-fv-regex-regexp="^[0-9|a-z|A-Z|-]{4}$" data-fv-regexp-message="Al menos 4 Caracteres Válidos"/>
</td>

<td class="form-group">
  <input class="form-control" type="text" name="amounts[]" id="amounts_0" size="10" data-fv-notempty="true" data-fv-notempty-message="Valor Requerido" data-fv-regexp="true" data-fv-regexp-regexp="^[0-9]+|[0-9]\.[0-9]+$" data-fv-regexp-message="Valor Numérico esperado" onchange="calcAmount(this)"/>
</td>
<td class="form-group">
  <input class="form-control" type="text" name="subtots[]" value="0.00" id="subtots_0" size=10 readonly/>
</td>
<td class="col-xs-1">
  <a class="badge bg-green addButton"><i class="fa fa-plus-circle"></i></a>
</td>

也就是说,除非输入的文本以数字开头,否则名为 concepts[] 的输入不会生效。不过右边data-fv-regexp-message开火了

对不起大家。解决了。我的错。

简短说明

HTML5 和 js 表单验证方法的混合用于相同的输入。

详细解释

当我将行(带有新字段)动态添加到 table,并将这些字段添加到表单验证时

var fields = $('#tr_' + i).find(":input:not([readonly])"); $('#myform').formValidation('addField', inputs);

并且第一行(其输入)已经通过 HTML5 data-fv-* 属性验证。所以不知何故验证中断