jQuery输入电话号码的掩码 [英] jQuery input mask for phone number

查看:131
本文介绍了jQuery输入电话号码的掩码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望用户输入的内容能自动填写电话号码的标点符号,以便看起来像这样(xxx) xxx-xxxx.这是我的HTML代码:

I want a user's input to autofill the punctuation of a phone number in order to look like this (xxx) xxx-xxxx. This is my HTML code:

  <div class="form-group">
    <label class="control-label col-sm-2">Phone Number:</label>
    <div class="col-sm-10">          
      <input type="text" class="form-control" name="phoneNumber"
           id="phoneNumber" value="<?php echo $row["phoneNumber"];?>">
    </div>
  </div>

要完成此任务,我还需要做什么?我正在尝试使用jQuery和输入掩码.

What else do I need to do to complete this task? I am trying to use jQuery and an input mask.

推荐答案

您可以通过使用Input Mask jQuery扩展来实现.

You can accomplish this by using the Input Mask jQuery extension.

$('#phoneNumber').inputmask("(999) 999-9999");

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://rawgit.com/RobinHerbots/jquery.inputmask/3.x/dist/jquery.inputmask.bundle.js"></script>

<label class="control-label col-sm-2">Phone Number:</label>
  <div class="col-sm-10">          
  <input type="text" class="form-control" name="phoneNumber" id="phoneNumber" value="">
</div>

这篇关于jQuery输入电话号码的掩码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆