I would like to partially mask a username field to this format ta*********@company.com. I tried using a converter but it doesn't work. What is the best way to achieve this in xamarin.
<Entryx:Name="Email" Text="{Binding Model.Email , Converter={StaticResource maskedEmailConverter}}" />
public class MaskedEmailConverter : IValueConverter
{
private string _value;
public object Convert(object value, Type targetType,
object parameter, CultureInfo culture)
{
var str = (value ??"").ToString();
_value = str;
var maskedStr = "";
if (!string.IsNullOrEmpty(str) && str.Length>2)
{
var domainStr = str.IndexOf('@');
var lengthOfMask = domainStr - 2;
maskedStr = str.Substring(0, 2) + new string('*', lengthOfMask) + str.Substring(domainStr);
}
return maskedStr;
}
public object ConvertBack(object value, Type targetType,
object parameter, CultureInfo culture)
{
return value;
}
}