Skip to Content
avatar image
Former Member

How to check incoming field value is complete Alphabates or Not

Hi all,

I have the requirement like this

I have Two input values 1) Receiving Code 2) Delivery No

If the Receiving Code is Complete Alphabets means i have to concatenate last 3 digits of Delivery No to receiving Code and pass it, else Pass the Receiving code as it is.

For Ex1:

Receiving code = ABCD

Delivery No = 1234

Result shld be ABCD234

Ex2:

Receiving code = AB879

Delivery No = 1234

Result shld be ABCD879

Ex3:

Receiving code = 9999

Delivery No = 1234

Result shld be 9999

Please help me on this

Regards

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

4 Answers

  • Best Answer
    avatar image
    Former Member
    Oct 02, 2009 at 07:40 PM

    Hi Vamsi,

    The String has a matches(), which will tell you whether the string is a regular expression or not.

    Try this -

    if (myString.matches("[a-zA-z0-9]*"))

    // alpha-numeric

    else

    // Not alpha-numeric;

    Change the code as per your requirement.

    Let us know if you have more issues with this.

    Regards,

    Neetesh

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi Nitish,

      I checked in this way also

      if (LCode.matches("a-zA-Z"))

      return LCode+DelNo.substring(7,10);

      else

      return LCode;

      But always it is returning else part only.

      Could you please give me the UDF code for my above mentioned requirement please

      Regards

  • avatar image
    Former Member
    Oct 02, 2009 at 09:01 PM

    Hi Vamsi,

    You need to 2 udfs for this. One for finding whether numeric or string and the other for taking the substring from 3rd position to the end. Because the end length is not same standard function dont support.

    First udf: Create a Value udf with two inputs a and b and name it as isRegex. Add this code:

    Imports: java.util.regex.*;

    Pattern pat=Pattern.compile(b);

    Matcher m=pat.matcher(a);

    if(m.find())

    return m.group();

    else

    return "true"; //This will return true if the input is string else the input will be returned.

    Second udf: Create a Value udf with two inputs a and b and name it as stringfrom3rdposition. Add this code:

    Imports: java.*;

    int i = Integer.parseInt(a);

    String c = b.substring(3,i);

    return c;

    Now map like this:

    Receiving Code (first input to udf1) --> isRegex

    [0-9] (second input to udf1 please dont forget[ ] brackets. best copy as it is and when you put you should like this [[0-9]])

    output of regex(first input to equals function)-->equalsS(text function)

    true (constant)

    So output of equals --> if -->

    for then: Deliveryno (first argument to udf2)--> length --> stringfrom3rdposition (udf2)

    Deliveryno (second argument to udf2)

    concat Receivingcode and output of udf2 give to then part

    and in else part give Receivingcode. Hope this makes sense.

    Receivingcode -->

    Deliveryno>length>

    udf2 ---> ---> concat

    Deliveryno-->

    then

    Receivingcode -->

    isRegex(udf1) --> equalsS (text funciton) --> -->output

    [0-9] --> true -->

    else

    Receivingcode

    I tested it and it works fine for me . Give a try and let us know.

    Regards,

    ---Satish

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Suraj S.R.

      Hi Suraj,

      What ever you are saying is not possible here, because iam using 2 udf's as per the Satish's Suggession.

      Please check the Screenshot of My Mapping

      Iam able to get the values till Target side field, but to Target field its not reaching.

      Please help me on this to get this valu inside the target field.

  • avatar image
    Former Member
    Oct 02, 2009 at 09:07 PM

    Hi VAmsi,

    In your 2n example:

    Ex2:

    Receiving code = AB879

    Delivery No = 1234

    Result shld be ABCD879

    The result is wrong. Accorindg to logic you gave it should be AB879. Probably a typo. If yes then the udf which I hv given should work.

    Regards,

    ---Satish

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 05, 2009 at 05:27 PM

    This Code Solved my Issue

    Imports java.util.regex.Pattern;

    public String LocationCode(String locationCode,String deliveryNumber,Container container){

    if((Pattern.matches(".*
    p{Digit}", locationCode)) != true){

    int dnLength = deliveryNumber.length();

    locationCode = locationCode + deliveryNumber.substring(dnLength - 3, dnLength);

    }

    return locationCode;

    }

    Thanks for all your inputs, Especially Satish

    Thanks a lot for the support

    Add comment
    10|10000 characters needed characters exceeded