SoFunction
Updated on 2025-04-10

Collection of js form verification control codes page 3/3


5. Digital format verification
---------------------------------------      
//Function name: fucCheckNUM
//Function introduction: Check whether it is a number
//Particle description: Number to be checked
//Return value: 1 is a number, 0 is not a number
function fucCheckNUM(NUM)     
{     
var i,j,strTemp;     
strTemp="0123456789";     
if ( == 0)     
return 0     
for (i=0;i<;i++)     
{     
j=((i));     
if (j==-1)     
{     
//It means that there are characters but not numbers
return 0;     
}     
}     
//The description is a number
return 1;     
}     

6. Phone number format verification
---------------------------------------      
//Function name: fucCheckTEL
//Function introduction: Check whether it is a phone number
//Parameter description: string to check
//Return value: 1 is legal, 0 is illegal
function fucCheckTEL(TEL)     
{     
var i,j,strTemp;     
strTemp="0123456789-()# ";     
for (i=0;i<;i++)     
{     
j=((i));     
if (j==-1)     
{     
//It means that there are illegal characters.
return 0;     
}     
}     
//Instructions are legal
return 1;     
}    

7. A function to determine whether the input is Chinese
---------------------------------------      
function ischinese(s){   
var ret=true;   
for(var i=0;i<;i++)   
ret=ret && ((i)>=10000);   
return ret;   
}    

8. A comprehensive function to judge the legitimacy of user input
---------------------------------------      
<script language="javascript">  
//Limit the number of bits of input characters to start
//m is the user input, n is the number of digits to be limited
function issmall(m,n)  
{  
if ((m<n) && (m>0))  
  {  
  return(false);  
  }  
else  
{return(true);}  
}  

9. Determine whether the password is entered consistently
---------------------------------------      
function issame(str1,str2)  
{  
if (str1==str2)  
{return(true);}  
else  
{return(false);}  
}  

10. Determine whether the user name is a number letter sliding line
---------------------------------------      
function notchinese(str){ 
var reg=/[^A-Za-z0-9_]/g 
    if ((str)){ 
    return (false); 
    }else{ 
return(true);    } 


2.8. General check function for form text field
---------------------------------------      
Function: Detect all input texts that must be non-empty, such as name, account, email address, etc.
This verification is now only for text fields. If you want to target other domain objects in form, you can change the judgment conditions.

How to use: Add title text to the text field to be detected. The text is a prompt message, the Chinese name of the field you want to prompt to the user. For example, to detect username
The html is as follows <input name="txt_1" title="name">. Of course, it is best to use visual tools such as dreamweaver to edit the domain.
If you want to detect numeric type data, then unify the id of the domain into sz.
It is troublesome to judge date types in JavaScript, so there is no program for date type verification. Experts can add it.

The program is relatively grass, just provides an idea. Throwing bricks and attracting jade! :)
Oh, by the way, function call method: < form onsubmit="return dovalidate()">

function dovalidate()
{
fm=[0]//Only detect one form, if it is multiple, the judgment condition can be changed
    for(i=0;i<;i++)
    {  
//The detection and judgment conditions can be modified according to the type
    if(fm[i].()=="INPUT" &&fm[i].()=="TEXT" && (fm[i].title!=""))

         if(fm[i].value="/blog/="")//
         {
str_warn1=fm[i].title+"cannot be empty!";
         alert(str_warn1);
        fm[i].focus();
         return false;         
         }
if(fm[i].()=="SZ")//Digital verification
         {
                 if(isNaN(fm[i].value))
{ str_warn2=fm[i].title+"Incorrect format";
                alert(str_warn2);
                fm[i].focus();
                 return false;
                 }
        }
    }
    return true;
}
Previous page123Read the full text