Formatting Phone Numbers

I noticed a recent post on the LANSA2 Yahoo Group that was requesting the best method of scrubbing a user entered phone number to format it in a certain way.

There were no LANSA centric solutions given, and some of the other solutions may have worked just fine, but as this was a LANSA forum, I thought I would throw a LANSA solution in.

I could not find any real elegant solution in LANSA (like regex), but have created a small routine which would scan the input string remove all non-numeric characters and reformat based on a format passed in from another input string.

Currently this only handles 10 and 14 digit phone numbers. (14 has the country code in front. E.g. 011 for North America). I will create a similar routine another time for credit card formatting.

Simply put this method routine in your RDMLX code, and call it using the following statement(s). The method “FormatPhoneNumber” takes 2 parameters. 1) The input string to be formatted and 2) the format that will be used with an &# for each part of the phone number.


The first call above handles 14 digit phone and the second handles 10 digit phone numbers.

The code is shown below, and can be downloaded here.