Skip to content

monster.util.unformatPhoneNumber()#

Syntax#

monster.util.unformatPhoneNumber(phoneNumber[, specialRule]);

Parameters#

phoneNumber: String OR Number (mandatory)#

Formated US phone number to unformat.

specialRule: keepPlus String (optional)#

Only one value: keepPlus. If specified, the number will keep the +.

Return#

This method returns a String with the one of the following formats: +1NPANXXXXXX, 1NPANXXXXXX or NPANXXXXXX.

Description#

The monster.util.unformatPhoneNumber() method is used to easily unformat US phone numbers. If the phone number to unformat contains +1, you can choose to keep it by specifying the specialRule parameter.

Examples#

  • Unformat phone number with +1

    var phoneNumber = '+1 (415) 123-4567',
        unformattedPhoneNUmber = monster.util.unformatPhoneNumber(phoneNumber);
    
    console.log(unformattedPhoneNUmber);
    // output: "14151234567"
    

  • Unformat phone number without +1

    var phoneNumber = '(415) 123-4567',
        unformattedPhoneNUmber = monster.util.unformatPhoneNumber(phoneNumber);
    
    console.log(unformattedPhoneNUmber);
    // output: "4151234567"
    

  • Unformat phone number and keep +

    var phoneNumber = '+1 (415) 123-4567',
        unformattedPhoneNUmber = monster.util.unformatPhoneNumber(phoneNumber, 'keepPlus');
    
    console.log(unformattedPhoneNUmber);
    // output: "+14151234567"