【问题标题】:How to NOT show glyphicon-ok if field is left empty?如果字段为空,如何不显示 glyphicon-ok?
【发布时间】:2016-08-03 08:50:13
【问题描述】:

我有一个“txtPhone”输入过滤器,它不是强制性的,但只能接受电话号码,所以:

 <label class="control-label">Phone</label>
<input type="text" id="txtPhone" class="form-control intonly" maxlength="12" placeholder="Phone" name="Phone">

引导验证

Phone: {
                        validators: {
                            regexp: {
                                regexp: /^((091|\+91)?|\((091|\+91)?\)|(91)?|\(91\)|0)? ?[7-9][0-9]{9}$/,
                                message: 'The Indian Phone No must contain 10 digits'
                            },

                        }
                    },

但是当我点击文本框中显示的提交按钮时。

【问题讨论】:

  • 但这不是强制性的。
  • 那么问题出在哪里?如果该字段为空,则有效...
  • 如果字段为空,则不需要 glyphicon-ok。这是我的要求。

标签: jquery asp.net twitter-bootstrap jquery-ajaxq


【解决方案1】:

在JesusGrace长期挣扎之后,我找到了答案

  Bootstrap Validation

     Phone: {
                     enabled: false,
                    validators: {
                        regexp: {
                            regexp: /^((091|\+91)?|\((091|\+91)?\)|(91)?|\(91\)|0)? ?[7-9][0-9]{9}$/,
                            message: 'The Indian Phone No must contain 10 digits'
                        },

                    }
                },


        .on('keyup', '[name="Phone"]', function () {
                var isEmpty = $(this).val() == '';
                $('#form1')
                       .formValidation('enableFieldValidators', 'Phone', !isEmpty);
                // Revalidate the field when user start typing in the Phone field
                if ($(this).val().length == 1) {
                    $('#form1').formValidation('validateField', 'Phone')
                }
            })

【讨论】:

    猜你喜欢
    • 2018-09-01
    • 2018-07-22
    • 2020-04-13
    • 2014-04-09
    • 1970-01-01
    • 2021-09-02
    • 2022-08-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多