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

Parents
  • 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
        )
      )
    )

Reply
  • 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
        )
      )
    )

Children
No Data