SoFunction
Updated on 2025-04-10

Collection of JS Form Verification Control Codes Page 2/3


2.5  Judgement of the legality of Chinese/English/Number/Email Address

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

function  isEnglish(name)  //English value detection
{  
if(  ==  0)
return  false;
for(i  =  0;  i  <  ;  i++)  {  
if((i)  >  128)
return  false;
}
return  true;
}

function  isChinese(name)  //Chinese value detection
{  
if(  ==  0)
return  false;
for(i  =  0;  i  <  ;  i++)  {  
if((i)  >  128)
return  true;
}
return  false;
}

function  isMail(name)  //  E-mail value detection
{  
if(!  isEnglish(name))
return  false;
i  =  ("  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)  //Numerical detection
{  
if(  ==  0)
return  false;
for(i  =  0;  i  <  ;  i++)  {  
if((i)  <  "0"  ||  (i)  >  "9")
return  false;
}
return  true;
}

function  CheckForm()
{  
if(!  isMail())  {  
alert("Your email is illegal!");
();
return  false;
}
if(!  isEnglish())  {  
alert("The English name is illegal!");
();
return  false;
}
if(!  isChinese())  {  
alert("The Chinese name is illegal!");
();
return  false;
}
if(!  isNumber())  {  
alert("Zip code is illegal!");
();
return  false;
}
return  true;
}
//-->
</SCRIPT>

2.6 Characters that cannot be entered in a limited form item

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

function  contain(str,charset)//   The string contains the test function
{  
var  i;
for(i=0;i<;i++)
if(((i))>=0)
return  true;
return  false;
}

function  CheckForm()
{  
if  ((contain(,  "%\(\)><"))  ||  (contain(,  "%\(\)><")))
{  
alert("Illegal character entered");
();
return  false;
}
return  true;
}
//-->
</script>  

1. Check whether a string is composed of numbers.
---------------------------------------       
<script language="Javascript"><!--           
function checkNum(str){return (/\D/)==null}           
alert(checkNum("1232142141"))           
alert(checkNum("123214214a1"))           
// --></script>         

2. How to determine whether it is a character?
---------------------------------------       
if (/[^\x00-\xff]/(s)) alert("Contains Chinese characters");
else alert("all characters");

3. How to determine whether Chinese characters are included?
---------------------------------------        
if (escape(str).indexOf("%u")!=-1) alert("Contains Chinese characters");
else alert("all characters");

4. Email format verification
---------------------------------------      
//Function name: chkemail
//Function introduction: Check whether it is Email Address
//Parameter description: string to check
//Return value: 0: No 1: Yes
function chkemail(a)     
{ var i=;     
var temp = ('@');     
var tempd = ('.');     
if (temp > 1) {     
if ((i-temp) > 3){     
if ((i-tempd)>0){     
return 1;     
}     

}     
}     
return 0;     
}      
 
Previous page123Next pageRead the full text