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.
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
| Name | Type | Return Type | Supported Script Types | Description |
|---|---|---|---|---|
format.PhoneNumberFormatter | Object | Object | Client and server scripts | The object that formats the phone number to a string. |
PhoneNumberFormatter.format(options) | Method | string | Client and server scripts | Formats the phone number object to a string. |
format.PhoneNumberFormatType | Enum | enum | Client and server scripts | Holds values for phone number format types. |
format.Country | Enum | enum | Client and server scripts | Holds 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
| Name | Type | Return Type | Supported Script Types | Description |
|---|---|---|---|---|
format.PhoneNumberParser | Object | Object | Client and server scripts | The object that parses the string into a phone number. |
PhoneNumberParser.parse(options) | Method | Object of type PhoneNumber | Client and server scripts | Parses 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:
1// Additional code ...2var origNumberStr = "602547854ext.154";3 4var pnParser = format.getPhoneNumberParser({5 defaultCountry: format.Country.CZECH_REPUBLIC6});7var phoneNumber = pnParser.parse({8 number: origNumberStr9});10 11var pnFormatter = format.getPhoneNumberFormatter({});12var strNumber = pnFormatter.format({13 number: phoneNumber14});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.
Frequently Asked Questions (4)
Are the Phone Number Formatter and Parser objects applicable to both client and server scripts?
Do I need to set a default country for parsing phone numbers?
How do the Phone Number Formatter and Parser handle extensions in phone numbers?
Does the format module in SuiteScript provide enums for country and phone number format types?
Was this article helpful?
More in SuiteScript
- SuiteScript 2.1 Enhancements in NetSuite February Updates
SuiteScript 2.1 now supports async features and PATCH method. Discover the latest API and SuiteProcurement improvements.
- Scheduling Map/Reduce Script Deployments in NetSuite
Learn to schedule map/reduce script submissions, including one-time and recurring options in NetSuite.
- Binary File Support in N/https Module for SuiteScript
SuiteScript enhances capabilities with binary file support in the N/https module, allowing improved data handling in external communications.
- API Governance Units Calculation in NetSuite 2026.1
NetSuite 2026.1 introduces examples illustrating API governance unit calculations for both user event and scheduled scripts.
