I have a textbox in which I am showing credit card or banking info. I want it to be masked ( in the code behind page_load event) so that user can see something like this: xxxxxxxxxxxx-9999.
Eg: string creditcard = 1234567812345678
I want to show like this: xxxxxxxxxxxx5678
Thanks!
Something like this might work for variable length text:
// create 4 less x's than the credit card length.
// then append that to the last 4 characters of the credit card
new string('x', creditcard.Length - 4) + creditcard.Substring(creditcard.Length - 4);
"xxxxxxxxxxxx" + creditcard.Remove(0,12)
As ISO/IEC 7812 credit card numbers have 16 digits.
If the credit card is not ISO/IEC and has another length please use greg's answer. Like AmEx with 15 digits and Diner's with 14. (I wasn't even aware of this as in Europe AmEx is not that common.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With