Format phone number as (00) 00000-0000

-1

I have a problem with the formatting of phone numbers on my website written in PHP.

In this form, the user enters their phone number:

    <div class="form-group">
      <label class="control-label" for="phoneMobile">
        <?php _e('Whatsapp "Recomendado"',); ?> <sup>*</sup>
      </label>
      <div class="controls">
        <?php UserForm::mobile_text(osc_user()); ?>
      </div>
    </div>

After saving every process, the phone appears in the user profile:

<li>
<h3>Whatsapp</h3>
<h1 class="name"><i class="fa fa-whatsapp"></i><?php printf('%s', osc_user_phone_mobile()); ?></h1>
</li>

I'm looking for a way for the number to appear formatted in the following pattern (xx) xxxxx-xxxx without using plugins or JS. The form is Bootstrap.

    
asked by anonymous 27.06.2018 / 04:17

1 answer

0

It has a very simple solution using the jquery.mask plugin

First, you can find jquery.mask at this link: link

Then, in your JS file, just put this function:

$(document).ready(function() {
    $("#telefone").mask("(00) 00000-0000")
})

With this little bit of code all your fields with "phone" id will already have the mask defined.

See this example working here: link

    
27.06.2018 / 04:36