<ValidationProperty("Value")>
Public Class SocialBox
    Inherits System.Web.UI.UserControl

    Property Value As String
        Get
            If txtDisplayed.Text.Contains("*") Then
                Return _GetSanitizedSocial(txtValue.Value)
            Else
                Return _GetFormattedSocial(txtDisplayed.Text)
            End If
        End Get
        Set(value As String)
            txtValue.Value = value
            txtDisplayed.Text = _GetMaskedSocial(value)
        End Set
    End Property

    ' Given something like ###-##-####, returns ###-##-####
    Private Function _GetFormattedSocial(src As String) As String
        Dim regExtract As New Regex("^(\d{3})[- ]?(\d{2})[- ]?(\d{4})$")
        Dim match = regExtract.Match(src)
        If match.Success Then
            Return match.Groups(1).Value & "-" & match.Groups(2).Value & "-" & match.Groups(3).Value
        Else
            Return ""
        End If
    End Function

    ' Given ###-##-####, returns ***-**-****
    Private Function _GetMaskedSocial(src As String) As String
        Dim regExtract As New Regex("^\d{3}-\d{2}-(\d{4})$")
        Dim match = regExtract.Match(src)
        If match.Success Then
            Return "***-**-" & match.Groups(1).Value
        Else
            Return ""
        End If
    End Function

    ' Given ###-##-####, returns ###-##-####
    Private Function _GetSanitizedSocial(src As String) As String
        Dim regExtract As New Regex("^(\d{3})-(\d{2})-(\d{4})$")
        Dim match = regExtract.Match(src)
        If match.Success Then
            Return match.Groups(1).Value & "-" & match.Groups(2).Value & "-" & match.Groups(3).Value
        Else
            Return ""
        End If
    End Function

End Class