Click here to Skip to main content
14,358,929 members
Rate this:
Please Sign up or sign in to vote.
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
[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.LabelFor(x => x.CC) @Html.TextBoxFor(x => x.CC)

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

Can anyone help..
Updated 24-Oct-12 5:56am
Sergey Alexandrovich Kryukov 22-Oct-12 15:22pm
Do you consider this is as safety? Ha-ha!
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.
Member 9359591 24-Oct-12 10:49am
Can any one help. I'm getting it how i have to but theres an error on String CC. I have put String CC = "1111 2222 3333 4444"; its displaying XXXX XXXX XXXX 4444. But as per view i'm entering a card number, but on confirmation page i'm getting XXXX XXXX XXXX 4444. which i should'nt. As i'm defaulting the string to String CC = "1111 2222 3333 4444"; i'm getting that output as XXXX XXXX XXXX 4444. As per my question. for the number i enter in biling i should get the same format but for the numbers entered on my page.what can i do

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

<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);




in MVC3

in place of value put @model.account

Monjurul Habib 30-Oct-12 17:17pm

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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100