nodejs中正则
// IP ipReg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/; // PORT portReg = /^([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])$/; if(ipReg.test(data.ip) != true){ UserNotification.error("请检查 IP 格式是否正确!"); } if(portReg.test(data.port) != true){ UserNotification.error("请检查 PORT 格式是否正确!"); }
// inner ip
// 前提:ip合法且满足如下要求
// 127.0.0.1 & localhost
// 10.0.0.0--10.255.255.255
// 172.16.0.0--172.31.255.255
// 192.168.0.0--192.168.255.255
const innerIpReg = /^(127\.0\.0\.1)|(localhost)|(10\.\d{1,3}\.\d{1,3}\.\d{1,3})|(172\.((1[6-9])|(2\d)|(3[01]))\.\d{1,3}\.\d{1,3})|(192\.168\.\d{1,3}\.\d{1,3})$/;