Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Is there a way to partially mask an entry field in xamarin?

$
0
0

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;
        }
    }

Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>