0

我花了将近 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正在开火。

4

1 回答 1

0

对不起人们。解决了。我的错。

简短说明

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

详细解释

当我动态地将行(带有新字段)添加到表中时,还将这些字段添加到 formvalidation 为

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

并且第一行(它的输入)已经通过 HTML5data-fv-*属性进行了表单验证。所以以某种方式验证中断

于 2017-04-06T13:28:55.347 回答