You need to sign in to do that
Don't have an account?
krishna casukhela 7
hide email with askterisk if present
Hello friends
I have a requirement as follows. I am explaining in detail.
I have a URL say https://ap2.salesforce.com?fanID=0032800000gufvJ in salesforce.
based on this FanID I will get the email of that user.
Now I have a visualforce page with standard controller="fan__c"
<apex:inputText name="email>
In aex controller:
string fanid="Apexpages.currentpage().getparameter('fanID');
if fanid != NULL
string emaladdress=[select Email from fan__c where ID=:fanID];
Now value in emailaddress should be stored in <apex:InputText name=Email>
if the email already exists it should be replaced with asterisk as follows.
for example : assume email is jose@gmail.com and if it exists for that particular ID then the contents of <apex:inputText> should be
j***@g****.com
If email doesnt exist for that FanID then contents of <apex:inputText> will contain mary@yahoo.co.in
I am literaly struggling with this so any will be rewarded with points
thanks
krishna
I have a requirement as follows. I am explaining in detail.
I have a URL say https://ap2.salesforce.com?fanID=0032800000gufvJ in salesforce.
based on this FanID I will get the email of that user.
Now I have a visualforce page with standard controller="fan__c"
<apex:inputText name="email>
In aex controller:
string fanid="Apexpages.currentpage().getparameter('fanID');
if fanid != NULL
string emaladdress=[select Email from fan__c where ID=:fanID];
Now value in emailaddress should be stored in <apex:InputText name=Email>
if the email already exists it should be replaced with asterisk as follows.
for example : assume email is jose@gmail.com and if it exists for that particular ID then the contents of <apex:inputText> should be
j***@g****.com
If email doesnt exist for that FanID then contents of <apex:inputText> will contain mary@yahoo.co.in
I am literaly struggling with this so any will be rewarded with points
thanks
krishna
a) if email and mobile phone exists then they should be masked. so this part is fine.
if mobilephone doesnt exists then user enters a new mobile phone number then while saving to sobject the it should be masked.
LBK: I don't understand this part. When the user enters Mobile Phone / Email address, you don't have to mask it until the page is refreshed (Because it is he / she who entered the values anyways).
When the page is refreshed, masking will be taken care already.
b) cud u pls let mw know the SAVE functionality, I need to save to sobject contact the values. adding command button
LBK: I have added Save functionality in the code. After save, the page will refresh itself. Make sure you change "THIS_VF_PAGE" with the actual VF page name in the code. Let me know how it goes.
All Answers
Please try this:
if (<condition to check if already exists>)
{
string eID = 'abcdefgh@gmail.com'; // Replace this eID with your string variable emailAddress.
integer len = eID.length();
string maskedId = eID.substring(0,1); // Masked Id will be your resultant Id
System.debug('0 ' +maskedId);
integer i;
for (i = 1; i< (len-4); i++)
{if (eID.substring(i,i+1) == '@')
{maskedId = maskedId + eID.substring(i, i+2);
i = i+1;
System.debug(i + ' ' + maskedId);
}
else{
maskedId = maskedId + '*';
System.debug(i + ' ' +maskedId);
}
}
maskedId = maskedId + eId.substring(i, eId.length()); //Put this masked Id in input text field
System.debug(maskedId);
}
else
{
//put unmasked email Id in the input field.
}
Please mark it as a answer if it solves your problem to benefit other viewers.
Below code should give you idea about how to implement this.
<apex:page standardController="fan__c" id="pg" >
<apex:form id="frm">
<apex:inputText id="actualEmail" />
<apex:inputHidden value="{!fan__c.email}" id="email"/>
</apex:form>
<script>
window.onload = function(){email()}
function email(){
var email = document.getElementById('pg:frm:email').value;
if(email != null){
var maskedEmail = maskEmail(email);
if(maskedEmail!= null && maskedEmail!=''){
document.getElementById('pg:frm:actualEmail').value = maskedEmail;
}
}
}
function maskEmail(emailToMask){
var maskid = "";
var prefix= emailToMask.substring(0, emailToMask.lastIndexOf("@"));
var postfix= emailToMask.substring(emailToMask.lastIndexOf("@"));
for(var i=0; i<prefix.length; i++){
if(i == 0 || i == prefix.length - 1) { ////////
maskid = maskid + prefix[i].toString();
}
else {
maskid = maskid + "*";
}
}
maskid =maskid +postfix;
console.log(maskid);
return maskid;
}
</script>
</apex:page>
Here is the VF and APEX extract from the sample implementation on Contact.
Let me know if this helps.
Hi LBK
Ur code works as per my expectation.
Please help me out in understanding two things.
a) if email and mobile phone exists then they should be masked. so this part is fine.
if mobilephone doesnt exists then user enters a new mobile phone number then while saving to sobject the it should be masked.
b) cud u pls let mw know the SAVE functionality, I need to save to sobject contact the values. adding command button
thanks
Krishna
a) if email and mobile phone exists then they should be masked. so this part is fine.
if mobilephone doesnt exists then user enters a new mobile phone number then while saving to sobject the it should be masked.
LBK: I don't understand this part. When the user enters Mobile Phone / Email address, you don't have to mask it until the page is refreshed (Because it is he / she who entered the values anyways).
When the page is refreshed, masking will be taken care already.
b) cud u pls let mw know the SAVE functionality, I need to save to sobject contact the values. adding command button
LBK: I have added Save functionality in the code. After save, the page will refresh itself. Make sure you change "THIS_VF_PAGE" with the actual VF page name in the code. Let me know how it goes.