Phone Number Formatter and Parser Objects in SuiteScript
Phone Number Formatter and Parser objects format phone numbers in SuiteScript, ensuring consistency across applications.
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
- Common SuiteScript Errors and Solutions for NetSuite
Common NetSuite script errors include INVALID_SCRIPT_DEPLOYMENT_ID and SSS_AUTHORIZATION_HEADER_NOT_ALLOWED. Learn effective solutions.
- Setting Field Values in SuiteScript for Effective Record
Learn to set field values in SuiteScript effectively, troubleshooting common errors and understanding data types.
- SuiteScript 2.1 Enhancements and API Updates in NetSuite
SuiteScript 2.1 enables execution of 2.0 scripts and supports PATCH method for enhanced API capabilities.
- Enhancements to SuiteScript User Role Context Clarification
SuiteScript updates clarify the user and role contexts for script executions, improving deployment understanding and management.
Advertising
Reach SuiteScript Professionals
Put your product in front of NetSuite experts who work with SuiteScript every day.
Sponsor This Category