【问题标题】:Restricting characters in bootstrap input field using pattern attribute使用模式属性限制引导输入字段中的字符
【发布时间】:2016-02-01 13:59:08
【问题描述】:

我在引导框架 php 页面中有以下字段。

<div class="col-xs-12 col-sm-10">
    <div class="form-group">
  <input type="text" name="inp_field1" id="inp_field1" class="form-control input-sm" placeholder="Do it here..." value='<?php echo($data_text_1)?>' required 
                                data-toggle="tooltip" title="Do it here..." tabindex="3">
    </div>
</div>

我需要限制几个字符,例如 /@。如何限制特定字符。不寻找什么可以被允许,但什么不能代替。理想情况下,如果可以使用模式属性来完成,那就太好了。

【问题讨论】:

    标签: html validation input twitter-bootstrap-3


    【解决方案1】:

    试试

    <div class="col-xs-12 col-sm-10">
        <div class="form-group">
         <input type="text" name="inp_field1" id="inp_field1" 
                 class="form-control input-sm" 
                 placeholder="Do it here..." value='<?php echo($data_text_1)?>' 
                 required data-toggle="tooltip" title="Do it here..."   
                 tabindex="3"
                 pattern="[^@\\]">
    </div>
    

    【讨论】:

    • 它为包括字母在内的字符提供高亮显示(红色框)。通常在输入受限字符时会突出显示
    • 是 html5 ... 不是特定于浏览器的 .. 那么应该可以工作
    猜你喜欢
    • 1970-01-01
    • 2012-01-29
    • 1970-01-01
    • 2013-03-06
    • 2015-11-13
    • 1970-01-01
    • 2012-02-11
    • 2014-10-14
    相关资源
    最近更新 更多