ParseNumber

A custom node that parses phone number

Overview

This custom n8n node parses and validates a phone number input. It is designed to take any string representing a phone number, validate it against the Mexican ("MX") numbering plan, and output the formatted international version of the number if valid. This node is useful in workflows where phone number normalization and validation are required, such as contact data cleaning, SMS sending automation, or CRM integrations.

Example use cases:

  • Validating user-submitted phone numbers before storing them.
  • Formatting phone numbers into a consistent international format for messaging services.
  • Filtering out invalid phone numbers from datasets.

Properties

Name Meaning
Parse Number Any number to be parsed and validated as a phone number.

Output

The node outputs a JSON object with a single field:

  • parsedNumber:
    • If the input is a valid Mexican phone number, this contains the phone number formatted in the international format (e.g., "+52 1 55 1234 5678").
    • If the input is invalid or cannot be parsed, it returns "not valid number".
    • If an unexpected error occurs during formatting, it returns "something went wrong".

No binary data output is produced by this node.

Example output JSON:

{
  "parsedNumber": "+52 1 55 1234 5678"
}

Dependencies

  • Uses the external library libphonenumber-js for parsing and validating phone numbers.
  • The node assumes the default country code "MX" (Mexico) for parsing.
  • No additional API keys or credentials are required.

Troubleshooting

  • Input too long: If the input number contains more than 12 digits (excluding non-digit characters), the node immediately returns "not valid number".
  • Invalid phone number: If the input cannot be parsed or is not valid according to the Mexican numbering plan, the output will be "not valid number".
  • Unexpected errors: If the formatting step fails unexpectedly, the output will be "something went wrong".

To resolve issues:

  • Ensure the input string contains a valid Mexican phone number.
  • Remove any extraneous characters or spaces that might interfere with parsing.
  • Confirm the input length does not exceed typical phone number lengths.

Links and References

Discussion