Skip to main content
August 10, 2021
Question

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

  • August 10, 2021
  • 2 replies
  • 0 views

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 ?

2 replies

acaciob0002
August 10, 2021

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.

stewart.burchell
August 10, 2021

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