Click here to Skip to main content
Rate this: bad
good
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
  [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.LabelFor(x => x.CC) @Html.TextBoxFor(x => x.CC)
In confirmation view
@Html.LabelFor(x => x.CC)  @Model.CC
Can anyone help..
Posted 22-Oct-12 9:22am
Edited 24-Oct-12 5:56am
v4
Comments
Sergey Alexandrovich Kryukov at 22-Oct-12 15:22pm
   
Do you consider this is as safety? Ha-ha!
--SA
Sastry_kunapuli at 22-Oct-12 16:49pm
   
try using a mask text box
Member 9359591 at 24-Oct-12 9:46am
   
what is a mask textbox
Member 9359591 at 24-Oct-12 9:47am
   
@alexandrovich: as of customer giving their card number is safety right..
Sergey Alexandrovich Kryukov at 24-Oct-12 13:41pm
   
It's actually not safe, to give a card number to non-trusted party.
--SA
Member 9359591 at 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: bad
good
Please Sign up or sign in to vote.

Solution 1

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
 
  Permalink  
v2
Comments
Monjurul Habib at 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)

  Print Answers RSS
0 OriginalGriff 7,800
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,790


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 30 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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