简体   繁体   中英

How can I display last 3 character in text box field with asterisk (password field)?

I'm currently working for a project in aspx C#, I want to user to type some text (eg phone number) in text box, while typing in the text field should shows asterisk sign (*) and last 3 digit of the phone number, example : *********810 Any one can help me? Thanks.

You can do this requirement by javascript using regex to replace last 3 digits at event onkeyup of input tag and need a hidden field to keep original value.

function mask(){
   //console.log($("#phone").val());
   $("#phone").val($("#phone").val().replace(/\d(?=\d{3})/g, "*"));
}

 function mask(){ //console.log($("#phone").val()); $("#phone").val($("#phone").val().replace(/\\d(?=\\d{3})/g, "*")); }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <input type="text" id="phone" onkeyup="mask()" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM