Parse a Czechia Phone Number

The following sample parses a Czech phone number and logs the resulting country code, extension, national number, number of leading zeros, carrier code, and raw input.

Note:

This sample script uses the require function so you can copy it into the SuiteScript Debugger and test it. You must use the define function in an entry point script (a script you attach to a script record and deploy). For more information, see SuiteScript 2.x Script Basics and SuiteScript 2.x Script Types.

          /**
 * @NApiVersion 2.x
 */
require(['N/format/i18n'], function(format) {
    var origNumberStr = "602547854ext.154";
    var pnParser = format.getPhoneNumberParser({
        defaultCountry: format.Country.CZECH_REPUBLIC
    });
    var phoneNumber = pnParser.parse({
        number: origNumberStr
    });

    /* after parsing:
       phoneNumber.countryCode is '420'
       phoneNumber.extension is '154'
       phoneNumber.nationalNumber is '602547854'
       phoneNumber.numberofLeadingZeros is 1
       phoneNumber.carrierCode is ' '
       phoneNumber.rawInput is '602547854ext.154'
    */

    var pnFormatter = format.getPhoneNumberFormatter({});
    var strNumber = pnFormatter.format({
        number: phoneNumber
    });  // strNumber is '+420 602 547 854 ext. 154'
}); 

        

General Notices