Show only the last 4 digits in the text box

I have a text box in which I display a credit card or banking information. I want it to be masked (in the code behind the page_load page event) so that the user can see something like this: xxxxxxxxxxxx-9999.

For example: creditcard = 1234567812345678

I want to show the following: xxxxxxxxxxxx5678

Thanks!

+6
source share
2 answers

Something like this might work for variable-length text:

// create 4 less x 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); 
+9
source
 "xxxxxxxxxxxx" + creditcard.Remove(0,12) 

Since the credit card numbers of ISO / IEC 7812 are 16 digits.

If the credit card is not ISO / IEC and has a different length, please use the greg answer. Like AmEx with 15 digits and Diner with 14. (I didn’t even know about it, as in Europe AmEx is not so common.)

+9
source

Source: https://habr.com/ru/post/889236/


All Articles