Sanitize Phone Number

The SanitizePhoneNumber function takes a phone number as input and removes all non-numeric characters. It uses Split to break the string into individual characters, IsMatch to filter digits, and Concat to reassemble the cleaned number.
SanitizePhoneNumber Function
// Function to sanitize a phone number by removing non-numeric characters
SanitizePhoneNumber(PhoneNumber: Text):
Text = Concat(
ForAll(
Split(PhoneNumber, "") As val,
If(
IsMatch(val.Value, "[0-9]", MatchOptions.Complete),
val.Value,
""
)
),
Value
);
Usage Example
Set(CleanedPhoneNumber, SanitizePhoneNumber(gblSelectedContact.Phone));
Description
The SanitizePhoneNumber
function removes all non-numeric characters from a phone number, returning only the digits. It processes the input string character by character, retains only digits, and returns a sanitized string containing only numeric values.
Parameters
- PhoneNumber (Text): The input phone number string to be sanitized.
Result
The variable CleanedPhoneNumber
will contain only the numeric characters from the input gblSelectedContact.Phone
.
Use Case
This function is ideal for:
- Cleaning phone numbers before validation or processing.
- Preparing phone numbers for storage in a database.
- Ensuring consistency in phone number formatting.
Notes
- Non-numeric characters such as spaces, parentheses, dashes, or special symbols will be removed.
- The function handles any text input, ensuring only numeric characters remain.
More Snippets from this Author
Page 1 of 0
Loading...
Loading...