cancel
Showing results for 
Search instead for 
Did you mean: 

UDF help for phone number format

Former Member
0 Kudos

Hi,

We have a source field Phone Number with the format

+CCCCC-AAAAA-PPPPPPPPPPPPPPPPPPPP+EEEEEEEEEE

CCCCC = optional country code with + as delimiter in the beginning (Max 5 length)

AAAAA = Area code (Max 5 length)

PPPPPPPPPPPPPPPPPPPP = Phone Number (Max 20 length)

EEEEEEEEEE = Optional extension (Max 10 length) with + as delimiter

On the target structure, we have three fields Area code, Phone number and extension. Country code doesn't need to map. Can we do this single UDF? or do we need three different UDFs?

Sample java code for UDF(s) would be very helpful.

Regards,

N@vin

Accepted Solutions (1)

Accepted Solutions (1)

former_member184681
Active Contributor
0 Kudos

Hi Navin,

If I got that right, since the country code and extension parts are optional, the input to the function when they are missing, can be: AAAAA-PPPPPPPPPPPPPPPPPPPP

If so, here is the UDF that produces four outputs:

for (int i = 0; i < input.length; i++) {

  if (! input.equals(ResultList.CC)) {

    String[] tokens = input[i].split("-");

    if (tokens.length == 2) {           //no country code part

      countryCode.addValue("");

      areaCode.addValue(tokens[0]);

      String[] tokens2 = tokens[1].split("\\+");

      if (tokens2.length == 1) {

        phoneNumber.addValue(tokens[1]);

        extension.addValue("");

      }

      else {

        phoneNumber.addValue(tokens2[0]);

        extension.addValue(tokens2[1]);

      }

    }

    else {           //country code found

      countryCode.addValue(tokens[0].replace("+",""));

      areaCode.addValue(tokens[1]);

      String[] tokens2 = tokens[2].split("\\+");

      if (tokens2.length == 1) {

        phoneNumber.addValue(tokens[2]);

        extension.addValue("");

      }

      else {

        phoneNumber.addValue(tokens2[0]);

        extension.addValue(tokens2[1]);

      }

    }

  }

  else {

    countryCode.addContextChange();

    areaCode.addContextChange();

    phoneNumber.addContextChange();

    extension.addContextChange();

  }

}

Regards,

Greg

Answers (2)

Answers (2)

Former Member
0 Kudos

hi NAvin ,

that is a simmple by using standard functions "subString" and "concat"and also use udf by posted earlier poster

if you need any mapping example , you  need to provide exatly example input and output values.

former_member184681
Active Contributor
0 Kudos

Well, I would say this could be simple if there were no optional fields. With those optional fields, the logic becomes much more complicated and the UDF I provided looks to be a more readable solution.

Regards,

Greg

Former Member
0 Kudos

Hi Greg,

Thanks for the code. I will try the mapping logic provided by you. It has to map three different fields on the target side.

You are right that country code and extension are optional. Not only that, length of each field is also varying.

Baskar - Considering above two requirements, please let me know if I can still use standards functions and achieve this.

Regards,

N@v!n

baskar_gopalakrishnan2
Active Contributor
0 Kudos

Considering option field value and value size varying using standard function is bit complicated to achieve but still possible. You got to check the length initially and then decide logic to use substring.  Doing UDF is better here as Greg said.

Former Member
0 Kudos

Hi Greg,

Thanks for the code. There is requirement where output of phoneNumber (3rd output from UDF) needs to be mapped to two different fields with first 3 numbers to phone prefix and last 4 numbers to line numbers. e.g., 4567890; 456 should go to one target field phone prefix and 7890 should go to another target field line number.

When I do substring (0,3) of 3rd output from UDF to phone prefix, it works fine. However I can't do substring (3,4) to send last 4 digits to line number. Can see if you can do substring of 3rd output form UDF and map it to two target fields?

Regards,

N@v!n

baskar_gopalakrishnan2
Active Contributor
0 Kudos

>When I do substring (0,3) of 3rd output from UDF to phone prefix, it works fine. However I can't do substring (3,4) to send last 4 digits to line number. Can see if you can do substring of 3rd output form UDF and map it to two target fields?

Are you using substring standard function or using substring in java string class? If you use substring standard function then do as follows..

for the first three numbers    use  substring (0,3)  start position o character count 3

for the next four numbers      use substring (3,7)  start position 3 charater count 4

Former Member
0 Kudos

Hi Baskar,

I am using substring standard function and have done the same as mentioned, however I still get the error for last four numbers.

Regards,

N@v!n

baskar_gopalakrishnan2
Active Contributor
0 Kudos

What error do you get? Are you sending 7 digit number in the source side? If the string length is less than 7 and try to use substring (3,7) then you will get error? Please provide the screenshot over here.

baskar_gopalakrishnan2
Active Contributor
0 Kudos

You can use simple standard function substring to extract each field from the source phone format string.  You really don't need UDF.  If you need UDF, then use the same substring method.