How to replace first 5 digit with * and remaining number will same ?

Hi,

I have to pass 10 digit number in the rule input, how to replace first 5 digit number with * and remaining 5 digit will same ?

  Discussion posts and replies are publicly visible

  • Hi there,

    There are multiple ways that you could achieve that, but you can try the code below to give you some idea:

    replace(1234567890,1,5,"*****")

    Just replace the numbers for your rule input.

    Hope that helps.

    Acacio B.

  • This will achieve what you've expressed:

    fn!concat("XXXXX", fn!right(ri!myNumber, 5))

    Note: it's best practice to encapsulate literals in constants so that a) their value can be maintained independently of the code where they're used and b) so that, by giving the constant a meaningful name, the code becomes more readable. e.g. instead of "XXXXX" you may have cons!PROJECT_PREFIX_TELEPHONE_NUMBER_MASKING_VALUE (or whatever is meaningful in your context). And now that you have the value in a constant you could interrogate that constant for it's length and use that value instead of the literal 5, so if the masking string in your constant ever changes in value or length the code will continue to work:

    fn!concat(
      cons!PROJECT_PREFIX_TELEPHONE_NUMBER_MASKING_VALUE,
      fn!right(
        ri!myNumber,
        fn!len(
          cons!PROJECT_PREFIX_TELEPHONE_NUMBER_MASKING_VALUE
        )
      )
    )