1 回答
郎朗坤
TA贡献1921条经验 获得超9个赞
没看到你的正则,但是可以这么粗略的校验下
var reg = /^[\d]{1,3}.[\d]{1,3}.[\d]{1,3}.[\d]{1,3}$/;
var regp = /^[\d]+$/;
var s = ['192.168.20.1.1', '192.168.20.1.1.1', '192.168.20.1a', '192.168.20.1', '192.168.20.10000'];
var p = [8080, 0, 333, 'a', '1+'];
for (let i = 0, len = s.length; i < len; i++) {
console.log('ip', s[i], reg.test(s[i]))
}
for (let i = 0, len = p.length; i < len; i++) {
console.log('port', p[i], regp.test(p[i]))
}
添加回答
举报
0/150
提交
取消