判断字符串是否为IP的正则

function is_ip(ip){
        let re =  /^([0-9]|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.([0-9]|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.([0-9]|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.([0-9]|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])$/;
        if(!re.test(ip)){
            return false;
        }
        return true;
    }

 

posted @ 2021-06-07 11:54  _迷途  阅读(233)  评论(0编辑  收藏  举报