﻿// JScript 文件

function trim(s){
   return s.replace(/(^\s*)|(\s*$)/g, "")
}

function IsEmail(e){
    var regex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
    
    if(trim(e.value)==""){
        return;
    }else{
        if(!regex.test(e.value)){
            alert("E-mail格式不正确!");
            e.focus();
        }
    }
}

function IsCard(e){
    var regex = /^\d{15}(\d{2}[A-Za-z0-9])?$/;
    
    if(trim(e.value)==""){
        return;
    }else{
        if(!regex.test(e.value)){
            alert("身份证格式不正确!");
            e.focus();
        }
    }
}

function IsUrl(e){
    var regex = /^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~@[\]\':+!]*([^<>\"\"])*$/;
    
    if(trim(e.value)==""){
        return;
    }else{
        if(!regex.test(e.value)){
            alert("网址格式不正确!");
            e.focus();
        }
    }
}

function IsTel(e){
    //var regex = /^((\(\d{3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,8}(\-\d{1,4})?$/;
    var regex = /^(0\d{2,3}\-?)?\d{6,8}(\-\d{1,4})?$/;
    
    if(trim(e.value)==""){
        return;
    }else{
        if(!regex.test(e.value)){
            alert("固定电话号码格式不正确!");
            e.focus();
        }
    }
}


function IsMobile(e){
    var regex = /^((\(\d{3}\))|(\d{3}\-))?1\d{10}$/;
    
    if(trim(e.value)==""){
        return;
    }else{
        if(!regex.test(e.value)){
            alert("手机号码格式不正确!");
            e.focus();
        }
    }
}


function IsQQ(e){
    var regex = /^[1-9]\d{4,10}$/;
    
    if(trim(e.value)==""){
        return;
    }else{
        if(!regex.test(e.value)){
            alert("QQ号码格式不正确!");
            e.focus();
        }
    }
}

function IsPost(e){
    var regex = /^[1-9]\d{5}$/;
    
    if(trim(e.value)==""){
        return;
    }else{
        if(!regex.test(e.value)){
            alert("邮编号码格式不正确!");
            e.focus();
        }
    }
}

function IsMoney(e){
    var regex = /^\d+(\.\d+)?$/;
    
    if(trim(e.value)==""){
        return;
    }else{
        if(!regex.test(e.value)){
            alert("货币格式不正确!");
            e.focus();
        }
    }
}

function IsNumeric(e){
    if(trim(e.value)==""){
        return;
    }else{
        if(isNaN(e.value)){
            alert("此处必须是纯数字!");
            e.focus();
        }
    }
}


