Phone Number Formatter and Parser Objects in SuiteScript

Phone Number Formatter and Parser objects enable formatting and parsing of phone numbers in SuiteScript for client and server scripts.

·3 min read·View Oracle Docs

TL;DR

The Phone Number Formatter and Parser objects in SuiteScript provide tools for formatting phone numbers into strings and parsing strings into phone number objects. This helps maintain consistency in phone number display across your NetSuite applications.

What are the Phone Number Formatter and Parser Objects?

The Phone Number Formatter and Phone Number Parser are key components provided by the format module in SuiteScript. They enable developers to manipulate phone numbers easily within their client and server scripts.

Phone Number Formatter

The format.PhoneNumberFormatter object is designed to format phone numbers into standardized string formats. This ensures that phone numbers are displayed consistently, which is essential for user interfaces and reporting.

Members of the Phone Number Formatter Object

NameTypeReturn TypeSupported Script TypesDescription
format.PhoneNumberFormatterObjectObjectClient and server scriptsThe object that formats the phone number to a string.
PhoneNumberFormatter.format(options)MethodstringClient and server scriptsFormats the phone number object to a string.
format.PhoneNumberFormatTypeEnumenumClient and server scriptsHolds values for phone number format types.
format.CountryEnumenumClient and server scriptsHolds values for different countries, aiding in formatting.

Phone Number Parser

The format.PhoneNumberParser object provides functionality to convert strings into phone number objects. This is particularly useful when input from users needs to be validated and formatted before being processed further.

Members of the Phone Number Parser Object

NameTypeReturn TypeSupported Script TypesDescription
format.PhoneNumberParserObjectObjectClient and server scriptsThe object that parses the string into a phone number.
PhoneNumberParser.parse(options)MethodObject of type PhoneNumberClient and server scriptsParses a string to create a phone number object.

Code Example

Here’s a simple example demonstrating how to use the Phone Number Parser and Formatter objects:

suitescript
1// Additional code ...
2var origNumberStr = "602547854ext.154";
3
4var pnParser = format.getPhoneNumberParser({
5 defaultCountry: format.Country.CZECH_REPUBLIC
6});
7var phoneNumber = pnParser.parse({
8 number: origNumberStr
9});
10
11var pnFormatter = format.getPhoneNumberFormatter({});
12var strNumber = pnFormatter.format({
13 number: phoneNumber
14});
15// expected output (strNumber) is '+420 602 547 854 ext. 154'
16// Additional code ...

Who Does This Affect?

  • Developers: Enhance scripts that require phone number management and display.
  • Administrators: Ensure phone numbers across the system meet formatting standards.

Key Takeaways

  • The Phone Number Formatter and Parser objects streamline phone number formatting and parsing in SuiteScript, ensuring consistency and compliance.
  • The objects support both client and server script types, making them versatile for various applications.
  • Using enums for format types and country selections simplifies code and enhances readability.

Source: This article is based on Oracle's official NetSuite documentation.

Frequently Asked Questions (4)

Are the Phone Number Formatter and Parser objects applicable to both client and server scripts?
Yes, both the Phone Number Formatter and Parser objects in SuiteScript support usage in client and server scripts.
Do I need to set a default country for parsing phone numbers?
While setting a default country is not mandatory, it aids in formatting by selecting the correct phone number structure based on the country's standards.
How do the Phone Number Formatter and Parser handle extensions in phone numbers?
The Phone Number Parser can convert a string containing a number with an extension into an object, and the Formatter can reformat it into a standardized string, including the extension.
Does the format module in SuiteScript provide enums for country and phone number format types?
Yes, the format module includes `format.Country` and `format.PhoneNumberFormatType` enums to facilitate country-specific formatting and standard format type selection.
Source: Phone Number Formatter Object Members Oracle NetSuite Help Center. This article was generated from official Oracle documentation and enriched with additional context and best practices.

Was this article helpful?

More in General

View all General articles →