Sometimes you need to remove personal identifiable information (PII) from the data you present in an application or on a web page. In the last couple of weeks this issue popped up twice, including one application which needs to be be HIPAA compliant. One solution is to mask any personal identifiable data so that the recipient can still verify the information, without sending it all in clear. I am sure you all seen this on for example credit card statements, with only the last 4 digits of your credit card number displayed.
I wrote a simple Lotusscript function to do this, and I thought I would share it so others can use it as well. You pass a string to mask, the number of characters to leave un-masked and where the unmasked characters should be displayed (“B” for beginning or “E” for end).
MsgBox masktext("TexasSwede",3,"B")This line would display Tex*******
MsgBox maskText("1234567890",4,"E")This line would display ******7890
Enjoy!
%REM
Function maskText
Description: Masks a text with asterisks, leaving the num first or
last characters visible. Direction is "B" (beginning) or "E" (end).
Created by Karl-Henry Martinsson - texasswede@gmail.com
%END REM
Function maskText(value As String, num As Integer, direction As string) As String
Dim tmp As String
Dim i As Integer
If Len(value)>num Then
If Left$(UCase(direction),1)="B" Then ' Start at the beginning
tmp = Left$(value,num)
For i = num+1 To Len(value)
tmp = tmp + "*"
Next
Else ' Start at the end
tmp = Right$(value,num)
For i = Len(value) To num+1 Step -1
tmp = "*" + tmp
Next
End If
Else
tmp = value
End If
maskText = tmp
End Function






