郎朗坤
没看到你的正则,但是可以这么粗略的校验下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]))}