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>
What else do I need to do to complete this task? I am trying to use jQuery and an input mask.
You can accomplish this by using the
Input Mask
jQuery extension.Currently for detecting any kind of phone number around the globe, the phone extension is more appropriate, since it checks already in a preexisting array of masks (no need to define a mask):
However, phone.js actually provides us a huge alias, where dynamic access to each item's details/metadata (such as the country) is possible while the user types (type in in the 2nd input to see it). So you may also create your own phone extension based on this huge array (3rd input).
This is all the same old Inputmask (which may also be jQuery-free now). Above I just depicted:
data-
attributes;alias: "abstractphone"
when extending.