1

In below response I am getting "43445567665" this value when I am mapping biomatricData.ninId:

biomatricData.ninId = 43445567665

Now I have to display only last 4 digit and rest should come like *

I have to change 43445567665 in below format

Like - *******7665

<View style={{ flexDirection: 'row', marginBottom: 10 }}>
  <RegularText text={'Nin Number :  '} textColor='grey' style={{ marginBottom: 5 }} />
  <Text>{biomatricData.ninId}</Text>
</View>
Peter B
  • 22,460
  • 5
  • 32
  • 69
Abhigyan Gaurav
  • 1,854
  • 6
  • 28
  • 58

4 Answers4

2

Put that biomatricData.ninId in variable then complete action given below and just use that variable for show.

use following regex.

var str = "43445567665";
var replaced = str.replace(/.(?=.{4,}$)/g, '*');
console.log(replaced);
Ashish
  • 6,791
  • 3
  • 26
  • 48
0

Try this code

var numToBeConverted = 327364829364;
String(numToBeConverted).split("").reverse().map((e, i) => i >= 4 ? "*" : e).reverse().join("");

You can make it a function if you want

function convertToBiometric(num) {
     return String(num).split("").reverse().map((e, i) => i >= 4 ? "*" : e).reverse().join("");
}
0

Can be achieved using Array methods like this.

let numToBeConverted = '43445567665';

function covert(num){
  let arr = Object.values(num);
  return  arr.splice(0, arr.length-4).fill('*').join('')
  + arr.splice(-4).join('');
}

console.log(covert(numToBeConverted));
//output - "*******7665"
Amruth
  • 5,792
  • 2
  • 28
  • 41
0

We can use String padding to add the * sign in our string values to convert our string in sensitive data

checkout the doc to apply string padding

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart

Jignesh Mayani
  • 6,937
  • 1
  • 20
  • 36