Laxmi
Laxmi

Reputation: 93

how to mask some text in radtextbox

I need to mask a input string having Pan number format ex.(ABCDE1234F) to (######234F) .

I have tried using maskedtextbox but it didn't help.

using below code :-

Upvotes: 1

Views: 265

Answers (2)

Raka
Raka

Reputation: 427

Add event OnTextChanged to your textbox with below code

private void textBox_TextChanged(object sender, EventArgs e)
{
    TextBox tb = sender as TextBox;
    if (tb != null && !string.IsNullOrWhiteSpace(tb.Text))
    {
        tb.Text = tb.Text.Remove(0, 6).PadLeft(10, '#');
    }
} 

Upvotes: 0

Sarath Mohandas
Sarath Mohandas

Reputation: 536

Please check this code, you can modify this code as per the textbox values

var cardNumber = "ABCDE1234F";

var firstDigits = cardNumber.Substring(0, 5);
Console.WriteLine(firstDigits);

var lastDigits = cardNumber.Substring(cardNumber.Length - 5, 5);
Console.WriteLine(lastDigits);

var requiredMask = new String('#', cardNumber.Length - firstDigits.Length);
Console.WriteLine(requiredMask);

var maskedString = string.Concat(requiredMask, lastDigits);
Console.WriteLine(maskedString);

Output

ABCDE
1234F
#####
#####1234F

Upvotes: 0

Related Questions