Friday, October 5, 2012

Masking SSN in C#

 public static string MaskSSN(string ssn)
        {
            string pattern = @"(?:\d{3})-(?:\d{2})-(\d{4})";
            return (null != ssn) ? Regex.Replace(ssn, pattern, "XXX-XX-$1") : string.Empty;
        }

2 comments: