Hi I went through many answers on this but couldn’t find a similar one which worked. Kindly help with this.
I have a script which hides mobile number inside <p></p>
tag, the present script hides any numbers added. We want this to be like it should hide numbers which are above 9 digits only. And also if it has
<span></span>
tag it should not hide the mobile number. Can we achieve this please.
We want it like this:
<p>Hide 1234567890<span>Show 0987654321</span></p>
Output will be: ‘Hide *** Show 0987654321’
<script>
$(document).ready(function() {
$('#hidenumber').find('p').text(function(i,txt) {
return txt.replace(/[1-9]+/,'***');
});
});
</script>
3
Answers
Try it like this:
In this updated script, the each function is used to iterate over each
element within the #hidenumber container. For each paragraph, it checks if there are any tags inside. If there are no tags, it applies the regular expression bd{10,}b to replace numbers with 10 or more digits with ***. The modified text is then set back as the content of the paragraph using the html function.
Please note that this script assumes that the container with the ID hidenumber contains the
elements you want to modify. Make sure to adjust the selector (#hidenumber) according to your HTML structure.
With this modification, the script will only hide numbers above 9 digits and exclude numbers within tags.
Try this:
Using the Node.TEXT_NODE will exclude text/numbers in the other elements such as span.
Adam (APB Reports)