Monthly Archives: September 2015

Formatting Phone Numbers – followup

The code which I originally put together on my previous blog entry was US centric…I have adjusted it to make it more flexible, and to be able to handle more countries.

The parameters have changed. 1) End users input 2) expected number of digits (after removing all other formatting) 3) Description of the target format (& denotes a substitution at that position. The single digit following an & denotes how many numbers to use from the phone number in that spot.

The full code can be downloaded from here

Calling the routine

Here is the code

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.