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 格式是否正确!");
}

猜你喜欢

转载自www.cnblogs.com/stellar/p/10785000.html