monster.util.formatPhoneNumber()

Syntax

monster.util.formatPhoneNumber(phoneNumber);

Parameter

  • phoneNumber (mandatory)

Type: String OR Number

US phone number to format.

Return

This method returns a String with the following format: +1 (NPA) NXX-XXXX

Description

The monster.util.formatPhoneNumber() method is used to easily format US phone numbers.

Examples

  • Format phone number starting with +1
var phoneNumber = '+14151234567',
    formattedPhoneNumber = monster.util.formatPhoneNumber(phoneNumber);

console.log(formattedPhoneNumber);
// output: "+1 (415) 123-4567"
  • Format phone number without +1
var phoneNumber = 4151234567,
    formattedPhoneNumber = monster.util.formatPhoneNumber(phoneNumber);

console.log(formattedPhoneNumber);
// output: "+1 (415) 123-4567"

Edit this page here