フォームJS

1195 ワード

<!-- lang: js -->
function checkReg(){ 
if(document.reg.name.value==" " || document.reg.name.value==null){ 
    alert('  :       !'); 
    document.reg.name.focus(); 
    return false; 
    } 
if(!checkName(document.name.value)){ 
    alert('  :     2-4   !');
    return false; 
    }
if(document.reg.phone.value==" " || document.reg.phone.value==null){ 
    alert('         !'); 
    document.reg.phone.focus(); 
    return false; 
    }
if(!checkPhone(document.reg.phone.value)){ 
    alert("        ,     !");
    document.reg.phone.focus(); 
    return false; 
    } 
}
function checkName(name){
    var nameVar = /^([u4E00-u9FA5])*$/;
    if( !nameVar.test(name) && name.length >= 2 && name.length <= 4){
        return true;
    }else{
        return false;
    }
}
function checkPhone(phone){
   var flag = false;
   var reg0 =  /^(([0\+]\d{2,3}-)?(0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/;   //     
   var reg1 =/^((\(\d{2,3}\))|(\d{3}\-))?(13|15|18)\d{9}$/;               //     
   if (reg0.test(phone)) flag=true; 
   if (reg1.test(phone)) flag=true; 
   return flag;
}
ソース:www.696 e.com