Simple function to Encryption on Mobile No,email id or any user information in react-native
Hii, EveryOne , today i am going to write a simple java script function , in which we change the format of number,
suppose you get a mobile number form back-end or from the user and now you want to encrypt that number ,
mobile no is - 9876543210 and you have to show the number in the following format
mobile no is - 98XXXXXX10 ,
if you are beginner in mobile application development you see this kind of situation,
so here is the function with the help of the this function you can handle the situation like this,
you can convert e-mail, mobile no, card no, name and any user information ,
const changeTheNumber=(number)=>{
var newNum = number.toString()
var res = '';
for(var i = 0; i<newNum.length; i++){
if (i > 1 && i < 8){
res = res + newNum[i].replace(newNum[i],'X')
//console.log(res)
}else
{
res = res + newNum[i]
}
}
//console.log(newNum)
//console.log(res)
return res
}
changeTheNumber is a arrow function in which i pass the number that i want to convert , in this function i send the number in parameter so i convert number into the string with the help of toString() javaScript method then i take an other variable res to store the result,
now run the for loop and the you condition in my case i run loop i= 0 to i is less than newNum("number converted into the string")
than i know in india number should be equal to 10 so i apply the condition is i is greater than 1 and less than 8 replace the value of i with x and then i sotre the result in my variable res,
and return the variable res now use this function where you want to encrypt the Number or email or any other information
Thank You
Comments
Post a Comment