1. 程式人生 > >js檢驗ip格式

js檢驗ip格式

function checkIp(ip) {
    varexp=/^(\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 = ip.match(exp);
    if(reg==null){
        return false;
    } else {
        return true;
    }
}