javascrapy 正则表达式验证 IP和MAC

var psrc = $('input[name="psrc"]').val()
var hwsrc = $('input[name="hwsrc"]').val()
var pdst = $('input[name="pdst"]').val()
var hwdst = $('input[name="hwdst"]').val()

var re = /^(\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 reg=/[A-Fa-f\d]{2}:[A-Fa-f\d]{2}:[A-Fa-f\d]{2}:[A-Fa-f\d]{2}:[A-Fa-f\d]{2}:[A-Fa-f\d]{2}/;

if(!psrc && !re.test(psrc)){
alert('源IP不合法!');
return
}
if(!hwsrc && !reg.test(hwsrc)){
alert('源MAC不合法!');
return
}
if(!pdst && !re.test(pdst)){
alert('目的IP不合法!');
return
}
if(!hwdst && !reg.test(hwdst)){
alert('目的MAC不合法!');
return
}

posted @ 2018-07-09 16:17  予沫笙  阅读(354)  评论(0编辑  收藏  举报