ip和port的正则验证

var ip = $("#txtIP").val();
var port = $("#txtPort").val();

// 正则表达式
var regip = /^(\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])$/;
var regport = /^([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-4]\d{4}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])$/;

// 返回结果
var isIp = regip.test(ip);
var isPort = regport.test(port);

posted @ 2020-07-13 10:06  就一个  阅读(1428)  评论(0编辑  收藏  举报