js驗(yàn)證身份證號

字號:


    function checkidcardno(){
    var str;
    var sn
    str=document.form.idcardno.value;
    str.trim;
    if(str.length==15||str.length==18){
    }
    else{
    alert(身份證號不正確);
    document.form.idcardno.select();
    document.form.idcardno.focus();
    return false;
    }
    for(var i=0;i<str.length;i++){
    sn=str.charat(i);
    if((sn>=0 && sn<=9 && i!=(str.length-1)) || ((sn>=0 && sn<=9) || sn==x || sn==x) && i==(str.length-1)){
    }
    else{
    alert(身份證號不正確);
    document.form.idcardno.select();
    document.form.idcardno.focus();
    return false;
    }
    }
    return true;
    }