Jump to content

Mask credit card information in text box


jebaraj

Recommended Posts

I need to display Credit card number with only last 4 digits visible.The remaining numbers should display as **

eg: If the credit card number is 2222 1111 3333 4444

its should display as **** **** **** 4444 in a textbox

Can anybody provide me a solution

Link to comment
Share on other sites

If you're looking to hide the number after it's been entered and submitted, you could use something like this:

 

<?php
$ccNum = "2222 1111 3333 4444";
print "<div>$ccNum</div>";
$ccNum_lastFour = substr($ccNum, -4);
$ccNum = preg_replace("~\d~", '*', $ccNum);
$ccNum = substr($ccNum, 0, -4) . $ccNum_lastFour;
print "<div>$ccNum</div>";
?>

 

 

If you're looking to hide the credit card as it's being typed into the form, you'll need to look into solution using a client-side option like JavaScript.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.