欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jquery中郵箱地址 URL網(wǎng)站地址正則驗(yàn)證實(shí)例代碼

 更新時(shí)間:2013年09月15日 15:54:10   作者:  
QQ網(wǎng)站有一個(gè)網(wǎng)站舉報(bào)的功能,看了一些js代碼覺得寫得很不錯(cuò),我就拿下來了,下面是一個(gè)email驗(yàn)證與url網(wǎng)址驗(yàn)證js代碼,分享給大家

email地址驗(yàn)證

復(fù)制代碼 代碼如下:

function checkEmail(){
    var email=$.trim($("#report_email").val());
    if(email == ""){
        $("#report_email").next('p').html("*請(qǐng)輸入郵箱地址!");
        return false;
    }
    var re = /^([a-zA-Z0-9]+[_|_|.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|_|.]?)*[a-zA-Z0-9]+.[a-zA-Z]{2,3}$/ig;
    if(!re.test(email)){
        $("#report_email").next('p').html("*郵箱地址格式錯(cuò)誤!");
        return false;
    }
    return true;
}

url地址驗(yàn)證

復(fù)制代碼 代碼如下:

function getUrlArray(e, type){
    var urls = $.trim($("#report_url_list").val());
    urls = urls.replace(/s*n+s*/ig,"n");
    $("#report_url_list").val(urls);
        //format the urls
    if(type == "blur"){
        reportUrlElm.val(urls);
    }
    if(e && e.keyCode == 13){
        reportUrlElm.val(urls + "n");
    }

    urls = urls.split("n");
    user_urls = urls;
    return urls;
}
function checkurls(e, type) {
    $("#errorList").find("span").hide();
    urls = getUrlArray(e, type);
    var urlfag = true;
    url_index = 0;
    var urlText="請(qǐng)?zhí)顚懪e報(bào)網(wǎng)站,您可以舉報(bào)多個(gè)網(wǎng)址,每行一個(gè),一次不超過20個(gè)。";
    if(!urls[0] || urls[0] == urlText){
        $("#report_url_list").val(urlText).css("color","#757575");
        $("#report_url_list").next('p').html('*請(qǐng)輸入正確的網(wǎng)址');
        $.urlfag=false;
        return false;
    }
    if(urls.length > 20){
            $("#report_url_list").next('p').html("已超過20個(gè),請(qǐng)分批舉報(bào)")
            $.urlfag=false;
            return false;
    }
    $.urlfag=true;
    for(url_index=0;url_index<urls.length;url_index++){
        $.urlfag = checkEachUrl(urls, url_index)  && $.urlfag ;
    }
    return  urlfag;
}
function checkEachUrl(urls, index){
    var e=urls[index];
    a = e.replace(/^http:///, "");

    if (a.indexOf("/") != -1) {
        a = a.substring(0, a.indexOf("/"));
    }
    var rg = /^((https?|ftp|news)://)?([w-]+.)+(.)+(:d+)?(/[w- ./?%&=]*)?$/i;
    if(!rg.test(a)){
        urlError("格式錯(cuò)誤",index,-1);
        return false;
    }
    if(inUrlArray(urls,index)){
        urlError("請(qǐng)不要舉報(bào)同一條網(wǎng)站",index,-1);
        return false; 
    }
    $.ajax({
        async:false,
        url:"http://api.pc.qq.com/tapi/url_report.php?url=http://"+a,
        dataType: "jsonp",
        method: "GET",
        success:function(a){
            if(a.is_existed=="yes"){
                urlError("該網(wǎng)址已被舉報(bào)",index,-1);
                $.urlfag= false;
            }
        }
    });
    urlError("正常",index,0);
    return true;
}

function inUrlArray(urls,index){
    var r=false
        for(i=index+1;i<urls.length;i++){
        a = urls[index].replace(/^http(s?):///, "");
        b = urls[i].replace(/^http(s?):///, "");
        if(a==b)
            r=true;
    }
    return r;
}
function  urlError(msg,index,type){
    type=type|| 0;
    var test = $("#errorList div").find("span").eq(index);
    test.show();
    if(type<0){
       test.attr('title',msg).css("background-position","-20px 0px");
    }else{
       test.attr('title',msg).css("background-position","0px 0px");
    }
}

相關(guān)文章

最新評(píng)論