lundi 26 avril 2021

JavaScript Regular Expression : I want to replace last 4 words of my variables

I'm currently making an e-commerce website with Spring, Java and Javascript. I want to hide the last four words of the users when they register a question like

hello123 >> hell**** stackoverflow >> stackover****

This is the code that I've written in my jsp.

<table>
<td id="userId">${ qna.userId }</td>
</table>

<script>
var userId = document.getElementById("userId");
    
    function maskingNumbers(userId) {
           return userId.replace(/\d(?=\d{4})/g, "*");
         }
</script>

Well, my "userId" still prints out on its original form. It would be really thankful if you be specific with the steps.




Aucun commentaire:

Enregistrer un commentaire