Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
2.75/5 (3 votes)
Hi friends,

Can any one help me do this, In a view i need to enter a credit card number of the customer and after the number is entered,on the confirmation page all the numbers should be displayed as * and display only last 4 digits. Using MVC3

In ViewModel
C#
 [Required]
[RegularExpression(@"^\d{16}$", ErrorMessage = "Card Number has 16 digits")]
       public string CC
       { get {
            String CC = "";
               String CCEncoded;
                CCEncoded = "XXXX XXXX XXXX " + CC.Substring( CC.Length-4, 4);
                return CCEncoded;  }
           set  { } }

In view
HTML
@Html.LabelFor(x => x.CC) @Html.TextBoxFor(x => x.CC)

In confirmation view
HTML
@Html.LabelFor(x => x.CC)  @Model.CC

Can anyone help..
Posted
Updated 24-Oct-12 4:56am
v4
Comments
Sergey Alexandrovich Kryukov 22-Oct-12 15:22pm    
Do you consider this is as safety? Ha-ha!
--SA
S@53K^S 22-Oct-12 16:49pm    
try using a mask text box
Member 9359591 24-Oct-12 9:46am    
what is a mask textbox
Member 9359591 24-Oct-12 9:47am    
@alexandrovich: as of customer giving their card number is safety right..
Sergey Alexandrovich Kryukov 24-Oct-12 13:41pm    
It's actually not safe, to give a card number to non-trusted party.
--SA

1 solution

html
HTML
<input id="account" value="1234567899876543" />

<input id="account_changed" />

var account = document.getElementById('account');
var changed = document.getElementById('account_changed');

changed.value = new Array(account.value.length-3).join('x') + account.value.substr(account.value.length-4, 4);


output:

1234567899876543

************6543

in MVC3

in place of value put @model.account

 
Share this answer
 
v2
Comments
Monjurul Habib 30-Oct-12 17:17pm    
5+

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900