How to match the IPv6 addresses using regex in JavaScript

1 Answer

0 votes
ipv6 = "2001:0db8:0000:0000:0000:ff00:0370:7331";

if (ipv6.match(/^(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$/)) {
  console.log("Valid");
}
else {
    console.log("Not valid");
}
  
  
  
/*
run:
 
Valid
  
*/

 



answered Apr 13, 2025 by avibootz
...