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

收藏的js表單驗證控制代碼大全第2/3頁

 更新時間:2007年08月14日 16:08:04   作者:  

2.5  中文/英文/數(shù)字/郵件地址合法性判斷

<SCRIPT  LANGUAGE="javascript">
<!--

function  isEnglish(name)  //英文值檢測
{  
if(name.length  ==  0)
return  false;
for(i  =  0;  i  <  name.length;  i++)  {  
if(name.charCodeAt(i)  >  128)
return  false;
}
return  true;
}

function  isChinese(name)  //中文值檢測
{  
if(name.length  ==  0)
return  false;
for(i  =  0;  i  <  name.length;  i++)  {  
if(name.charCodeAt(i)  >  128)
return  true;
}
return  false;
}

function  isMail(name)  //  E-mail值檢測
{  
if(!  isEnglish(name))
return  false;
i  =  name.indexOf("  at  ");
j  =  name  dot  lastIndexOf("  at  ");
if(i  ==  -1)
return  false;
if(i  !=  j)
return  false;
if(i  ==  name  dot  length)
return  false;
return  true;
}

function  isNumber(name)  //數(shù)值檢測
{  
if(name.length  ==  0)
return  false;
for(i  =  0;  i  <  name.length;  i++)  {  
if(name.charAt(i)  <  "0"  ||  name.charAt(i)  >  "9")
return  false;
}
return  true;
}

function  CheckForm()
{  
if(!  isMail(form.Email.value))  {  
alert("您的電子郵件不合法!");
form.Email.focus();
return  false;
}
if(!  isEnglish(form.name.value))  {  
alert("英文名不合法!");
form.name.focus();
return  false;
}
if(!  isChinese(form.cnname.value))  {  
alert("中文名不合法!");
form.cnname.focus();
return  false;
}
if(!  isNumber(form.PublicZipCode.value))  {  
alert("郵政編碼不合法!");
form.PublicZipCode.focus();
return  false;
}
return  true;
}
//-->
</SCRIPT>

2.6  限定表單項不能輸入的字符

<script  language="javascript">
<!--

function  contain(str,charset)//  字符串包含測試函數(shù)
{  
var  i;
for(i=0;i<charset.length;i++)
if(str.indexOf(charset.charAt(i))>=0)
return  true;
return  false;
}

function  CheckForm()
{  
if  ((contain(document.form.NAME.value,  "%\(\)><"))  ||  (contain(document.form.MESSAGE.value,  "%\(\)><")))
{  
alert("輸入了非法字符");
document.form.NAME.focus();
return  false;
}
return  true;
}
//-->
</script>  

1. 檢查一段字符串是否全由數(shù)字組成       
---------------------------------------       
<script language="Javascript"><!--           
function checkNum(str){return str.match(/\D/)==null}           
alert(checkNum("1232142141"))           
alert(checkNum("123214214a1"))           
// --></script>         

2. 怎么判斷是否是字符         
---------------------------------------       
if (/[^\x00-\xff]/g.test(s)) alert("含有漢字");          
else alert("全是字符");      

3. 怎么判斷是否含有漢字        
---------------------------------------        
if (escape(str).indexOf("%u")!=-1) alert("含有漢字");         
else alert("全是字符");           

4. 郵箱格式驗證    
---------------------------------------      
//函數(shù)名:chkemail     
//功能介紹:檢查是否為Email Address     
//參數(shù)說明:要檢查的字符串     
//返回值:0:不是 1:是     
function chkemail(a)     
{ var i=a.length;     
var temp = a.indexOf('@');     
var tempd = a.indexOf('.');     
if (temp > 1) {     
if ((i-temp) > 3){     
if ((i-tempd)>0){     
return 1;     
}     

}     
}     
return 0;     
}      
 

相關(guān)文章

最新評論