faiz khan

faiz khan

  • 2.1k
  • 21
  • 2.7k

using mask in credit card and customer mobile number

Aug 15 2022 7:12 PM

Hi friend.
I am creating some codes for masking. my requirement is that. once I enter customer mobile number and credit number into the textbox so some number should be convert into XX or * . like 9818233223, 3298472934729347
9818xxxx23 3298XXXXXXXX347
so i have created some codes but in console application it is working fine but once i am using these codes into window forms so it is not working. i am using Regex pattern please check my codes and make it clear for me

these are my codes 

public string CustomerMobileNumberMasking(string input)
        {
            string Output = "";
            input = string.Empty;


            try
            {
                if (!string.IsNullOrWhiteSpace(input))
                {
                    string pattern = @"\d(?!\d{0,1}$)";
                    string result = Regex.Replace(input, pattern, m => new string('*', m.Length));
                    Output = result;

               }
                return Output;
            }
            catch (Exception ex)
            {

               return Output;
            }
        }

 

 


Answers (1)