Reputation: 411
I managed to find and replace phone numbers with a very simple Java Script but need to delete the first character as easy as possible. Could anyone please give me an hint?
function cleanPhoneNumbers() {
document.body.innerHTML =
document.body.innerHTML.replace(
/\(?(0[0-9]{2,4})\)?\-?\/?\ ?[-. ]?([0-9]{7})/g,
"<a href='tel:+49$1$2'>$1-$2</a>"
);
}
</script>
Upvotes: 0
Views: 161
Reputation: 124
Easy, just modify your existing code so it looks like this...
<script type="text/javascript">
function cleanPhoneNumbers() {
document.body.innerHTML =
document.body.innerHTML.replace(
/\(?(0[0-9]{2,4})\)?\-?\/?\ ?[-. ]?([0-9]{7})/g,
"<a href='tel:+49$1$2'>$1-$2</a>"
).substring(1);
}
</script>
This updated code uses javascript substring command, the number 1 states where to start the string. 0 would be the whole string, 1 starts after the first character.
Upvotes: 2