Format phone number as (00) 00000-0000

Asked

Viewed 915 times

-1

I have a problem with formatting phone numbers on my site written in PHP.

In this form, the user enters his 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 the whole 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 am 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.

  • Do you need to be PHP? I’m sure there’s a mask in JS that already handles it perfectly. Luckily, a lot of people need to format phone numbers. I think if you search for "phone mask" right here on the site you will find a duplicate question of yours, already properly answered

  • It doesn’t have to be php, I already researched yes... I even have several examples of masks here. My doubt is how, and where will I put these codes? All the ways I tried didn’t work out.

1 answer

0

  • This is the big issue... I’m using a CMS, with folders and files to lose sight of, a forgotten point and the "error" comes from... Where should I put this plugin? ( in a specific folder type? in the root folder?) ... and another: "what would be my "JS" file? and where in this JS file should I put your code? my js folder has more than 10 JS files...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.