I am working on a JavaScript web network project and I need to use the substring method. However, I want to exclude the colon symbol from the substring because it represents a hexadecimal IP address. I do not want to include colons as part of the result. How can I achieve this?
For example, here is an IPv6 in the input field:
2001:2eb8:0dc1:54ed:0000:0000:0000:0f31
After substring from 1 to 12:
001:2eb8:0d
It shows that colons are accepted in the substring, but I actually need the result to be:
2001:2eb8:0dc1
In order to achieve this result by excluding colons, I am unsure of how to proceed.
In the code below, IpAddressInput is a regular input field where the IP address is entered.
Here is the code:
var IpValue = $('#IpAddressInput').val();
alert(IpValue.substr(1, (12) -1));