Validate IPv4 and IPv6 addresses
npm i proper-ip
CDN Links:
- https://cdn.jsdelivr.net/npm/proper-ip@1.0.0/proper-ip.js
- https://www.unpkg.com/proper-ip@1.0.0/proper-ip.js
// ES6
import properIp from "proper-ip";
// commonjs
const properIp = require("proper-ip");
properIp("192.168.0.1"); // True
properIp("10.0.0"); // False
properIp("2001:0db8:85a3:0000:0000:8a2e:0370:7334", "v6"); // True
properIp("hello world", "v6"); // False
Make sure to console.log()
the values to see the output!