简体   繁体   中英

Trying to mask a passport number in a textbox C#

So I have a textbox that holds the value of passport # but I need to mask out 6 of the 9 numbers with X or *.

I dont want to save the new passport number with the masked numbers I just want to view it but not sure if that is possible with how they set up the code before hand.

<asp:TextBox ID="txtPassportNumber" 
    runat="server" 
    MaxLength="9" 
    Text="<%# ((TSAPassenger) Container.DataItem).Passport.DocumentNumber %>" 
    Enabled="<%# IsOutsideTenDayCutoff %>" />

Code behind (button save event):

// Passport
TextBox tmpPassportNumber = item.FindControl("txtPassportNumber") as TextBox;
string encodedPassport = "XXXXXX" + tmpPassportNumber.Text.Remove(0, 6);
tmpPax.Passport.DocumentNumber = (tmpPassportNumber != null) ? tmpPassportNumber.Text : string.Empty;

I added the encodedPassport part but it will then save that to the DB if I use it. Any suggestions?

I would just mask out the input with a password box. Then you can have a confirmation to ensure they typed it correctly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM