<%@ Page Language="C#" %> <html> <head id="Head1" runat="server"> <script runat="server"> protected override void OnLoad(EventArgs e) { base.OnLoad(e); this.txtCreditCardNo.Attributes.Add("onkeyup", "javascript:Mask(this)"); } </script> <script language="javascript" type="text/javascript"> function Mask(obj, evt) { evt = (evt) ? evt : window.event var charCode = (evt.which) ? evt.which : evt.keyCode var txtValue = window.document.getElementById('txtCreditCardNo'); if ((charCode < 45 || charCode > 57) && charCode != 8 && charCode != 37 && charCode != 39) { alert("This field accepts numbers only"); txtValue.value = txtValue.value.substr(0, txtValue.value.length - 1); return false } else { var hdnValue = window.document.getElementById('hdnCreditCardNo'); if (charCode == 8) { if (hdnValue.value.length > txtValue.value.length) { hdnValue.value = hdnValue.value.substr(0, txtValue.value.length); } } else { hdnValue.value = hdnValue.value + String.fromCharCode(charCode); } } if (txtValue.value.length > 5) { txtValue.value = "*****" + txtValue.value.substr(5, txtValue.value.length); } else { var mask = ""; for (i = 0; i < txtValue.value.length; i++) mask += "*"; txtValue.value = mask; } return true } </script> </head> <body> <form id="form1" runat="server"> <asp:TextBox runat="server" ID="txtCreditCardNo" /> <asp:TextBox runat="server" ID="hdnCreditCardNo" Text="" /> </form> </body> </html>
Friday, June 25, 2010
How to mask credit card number using javascript - Asp.net Javascripts
Subscribe to:
Post Comments (Atom)
Azure Storage Account Types
Defferent Types of Blobs Block blobs store text and binary data. Block blobs are made up of blocks of data that can be managed individually...
-
Why we need asynchronous tasks? Execute a time consuming operations in parallel to the CLR thread which execute the request If you have ...
-
Demo: I was thinking a way to show images before actually uploading them to server. I would say to preview images using javascript. Obv...
1 comment:
Nice script, thank you.
Post a Comment