我想创建一个HTML文本输入字段,用于在用户输入时格式化电话号码。例如,当您在输入字段中键入电话号码时,例如0213858954555,输入字段会自动将电话号码格式化为(021)385-86111111
这是我目前的代码:
<div class="form_row clearfix custom_fileds owner_name">
<div class="col-sm-4">
<label class=r_lbl>Mobile numbers :
<!--<span class="required">*</span>-->
</label>
</div>
<div class="col-sm-8">
<input name="mobile_no" id="mobile_no" value="" type="text" class="textfield " placeholder=" "/>
</div>
</div>
答案 0 :(得分:3)
$(":input").inputmask();
$("#phone").inputmask({"mask": "(999) 999-9999"});
&#13;
<div class="form_row clearfix custom_fileds owner_name">
<div class="col-sm-4">
<label class=r_lbl>Mobile numbers :
<!--<span class="required">*</span>-->
</label>
</div>
<div class="col-sm-8">
<input name="mobile_no" id="phone" value="" type="text" class="textfield " placeholder=" "/>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/jquery.inputmask.bundle.js"></script>
&#13;
希望对你有帮助