Search code examples
javascriptasp.netpci-compliance

Asp.net mask credit card number in text box as being entered followed by validation and processing of credit card number


I am supporting an Asp.Net web applications which accepts and processes credit card. But due to new rules, I need to mask the credit card number as it's being entered. So if the first number is 4, it is visible until the next number is entered (e.g. 9), then the text box shows *9.

One way I could think of was to use JavaScript and hidden field to mask the credit card number on key up event and stored the CC in the hidden field. But I'm not sure if there is a better way of doing it. And also how to handle if user updates an existing number.

Are there any best practices for doing this? keep in mind I need those numbers and run validations before the credit card is processed and then process the credit card and store it in the database. I already have CC field in database encrypted.

Any suggestions/help would be highly appreciated.


Solution

  • There is a jQuery plugin that will do this for you:

    http://blog.decaf.de/2009/07/iphone-like-password-fields-using-jquery/