1. Only enter numbers and English:
<input onkeyup="value=(/[/W]/g,'') " onbeforepaste="('text',('text').replace(/[^/d]/g,''))" ID="Text1" NAME="Text1">
2. Only numbers can be entered:
<input onkeyup="value=(/[^/d]/g,'') " onbeforepaste="('text',('text').replace(/[^/d]/g,''))" ID="Text2" NAME="Text2">
3. Only input full-width:
<input onkeyup="value=(/[^/uFF00-/uFFFF]/g,'')" onbeforepaste="('text',('text').replace(/[^/uFF00-/uFFFF]/g,''))" ID="Text3" NAME="Text3">
4. Only Chinese characters can be entered:
<input onkeyup="value=(/[^/u4E00-/u9FA5]/g,'')" onbeforepaste="('text',('text').replace(/[^/u4E00-/u9FA5]/g,''))" ID="Text4" NAME="Text4">
--------------------------------------------------------------------------------
Verify illegal characters, sql
function vdf()
{
var i,j,name,value,message,length,type,a=,cb_name;
for (i=0; i<(-2); i+=3)
{
if (a[i].indexOf('#')!=-1)
{
name=fob(a[i].substr(0,a[i].indexOf('#')));
cb_name=fob(a[i].substr((a[i].indexOf('#')+1),a[i].length));
}
else
{
name=fob(a[i]); // Control name
}
message=a[i+1]; // Prompt message
type=a[i+2]; // Type
if (type!="r_time")
{
value=(/ +/g, ""); // control value
}
else
{
value=;
}
}
--------------------------------------------------------------------------------
// =======================================//
if (type=="r_cb")
{
e=(0).elements;
var flag=false;
for (i=0;i<;i++)
{
if (e[i]!=cb_name)
{
if (e[i].checked==true)
{
flag=true;
break;
}
}
if (i==-1)
{
break;
}
}
if (flag==false)
{
alert(message+"!/n"); // A prompt that appears when it is empty
return false;
}
}
// ======================================//
if (type=="r_sl")
{
if (==false)
{
alert(message+"!/n"); // A prompt that appears when it is empty
return false;
}
}
// ========================================//
if (type=="r")
{
if (value=="") // Determine whether it is empty
{
alert(message+"!/n"); // A prompt that appears when it is empty
();
();
return false;
}
}
// ===========================================/
if (type=="o_r")
{
if (value=="") // Determine whether it is empty
{
alert(message+"!/n"); // A prompt that appears when it is empty
return false;
}
}
// ======================================/
if (type=="r_china")
{
if ((/^[/u4e00-/u9fa5]+$/)==-1)
{
alert(message+"!/n"); // It cannot be empty
();
();
return false;
}
}
// ==========================================/
if (type=="r_num_char")
{
if (value=="")
{
alert(message+"!/n"); // A prompt that appears when it is empty
();
();
return false;
}
if ((/^[0-9a-zA-Z]+$/)==-1)
{
alert(message+"!/n"); // A prompt that appears when it is empty
();
();
return false;
}
}
// ========================== When it is not empty, fill in the number ===============//
if (type=="num")
{
if ((/^[0-9]+$/)==-1 && value!="")
{
alert(message+"!/n"); // It cannot be empty
();
();
return false;
}
}
// =========================================//
if (type=="r_num")
{
if (value=="")
{
alert(message+"!/n");
();
();
return false;
}
if ((/^[0-9]+$/)==-1)
{
alert(message+"!/n"); // It cannot be empty
();
();
return false;
}
}
// ======================================//
if (("r_num<")!=-1)
{
length=((('<')+1),); // Get the number after rn<
if (value=="") // Tips for empty
{
alert(message+"!/n");
();
();
return false;
}
If ((/^[0-9]+$/)==-1) // Not a reminder made by numbers
{
alert(message+"!/n");
();
();
return false;
}
If (>length) // Limits to limit the length of numbers
{
alert(message+"!/n");
();
();
return false;
}
}
// =====================================//
if (("r_num>")!=-1)
{
length=(((('>')+1),); // Get the number after rn<
if (value=="") // Tips for empty
{
alert(message+"!/n");
();
();
return false;
}
If ((/^[0-9]+$/)==-1) // Not a reminder made by numbers
{
alert(message+"!/n");
();
();
return false;
}
If (<length) // Limits to limit the length of the number
{
alert(message+"!/n");
();
();
return false;
}
}
// ==================== The number between a-b bits must be entered =================//
if (("r_num#<>")!=-1)
{
length=((('>')+1),);
length=(0,("-"));
length1=(((('-')+1),) // Get the number after rn<
if (value=="") // Tips for empty
{
alert(message+"!/n");
();
();
return false;
}
If ((/^[0-9]+$/)==-1) // Not a reminder made by numbers
{
alert(message+"!/n");
();
();
return false;
}
if (<length || >length1) // Limits to limit the length of the number
{
alert(message+"!/n");
();
();
return false;
}
}
// ======================================//
if (type=="r_float")
{
if (value=="")
{
alert(message+"!/n");
();
();
return false;
}
if ((/^[0-9]+$/)!=-1 || (/^([0-9]+)|([0-9]+/.[0-9]*)|([0-9]*/.[0-9]+)$/)!=-1)
{
return true;
}
else
{
alert(message+"!/n"); // It cannot be empty
();
();
return false;
}
}
// =============================================/
if (("email")!=-1)
{
if (!="")
{
if ((/^[_/.a-z0-9]+@[a-z0-9]+[/.][a-z0-9]{2,}$/i)==-1)
{
alert(message+"!/n");
();
();
return false;
}
}
}
// ==========================================/
if (("r_email")!=-1)
{
if (=="")
{
alert(message+"!/n");
();
();
return false;
}
if ((/^[_/.a-z0-9]+@[a-z0-9]+[/.][a-z0-9]{2,}$/i)==-1)
{
alert(message+"!/n");
();
();
return false;
}
}
// ========================================/
if (type=="r_date")
{
flag=true;
getdate=value;
if ((/^[0-9]{4}-(0[1-9]|[1-9]|1[0-2])-((0[1-9]|[1-9])|1[0-9]|2[0-9]|3[0-1])$/)==-1) // judging the input format is correct
{
flag=false;
}
else
{
var year=(0,('-')) // Get year
// The following operations are obtained by obtaining the month
var transition_month=(0,('-'));
var month=transition_month.substr(transition_month.lastIndexOf('-')+1,transition_month.length);
if (('0')==0)
{
month=(1,);
}
// The following operations get the date
var day=(('-')+1,);
if (('0')==0)
{
day=(1,);
}
//alert(month);
//alert(day)
//return false;
if ((month==4 || month==6 || month==9 || month==11) && (day>30)) // The date of 4,6,9, and November cannot exceed 30
{
flag=false;
}
If (month==2) // Judgment for February
{
if (LeapYear(year))
{
if (day>29 || day<1){ flag=false; }
}
else
{
if (day>28 || day<1){flag=false; }
}
}
else
{
flag=true;
}
}
if (flag==false)
{
alert(message+"!/n"); // A prompt that appears when it is empty
();
();
return false;
}
}
1. Length limit
<script>
function test()
{
if(>50)
{
alert("can't exceed 50 characters!");
();
return false;
}
}
</script>
<form name=a onsubmit="return test()">
<textarea name="b" cols="40" wrap="VIRTUAL" rows="6"></textarea>
<input type="submit" name="Submit" value="check">
</form>
2. It can only be Chinese characters
<input onkeyup="value="/oblog/(/[^/u4E00-/u9FA5]/g,'')">
3." can only be in English
<script language=javascript>
function onlyEng()
{
if(!(>=65&&<=90))
=false;
}
</script>
<input onkeydown="onlyEng();">
4. It can only be a number
<script language=javascript>
function onlyNum()
{
if(!((>=48&&<=57)||(>=96&&<=105)))
//Consider the numeric keys on the keyboard
=false;
}
</script>
<input onkeydown="onlyNum();">
5. Only English characters and numbers
<input onkeyup="value="/oblog/(/[/W]/g,"'') "onbeforepaste="('text',('text').replace(/[^/d]/g,''))">
6. Verify the fuel tank format
<SCRIPT LANGUAGE=javascript RUNAT=Server>
function isEmail(strEmail) {
if ((/^/w+((-/w+)|(/./w+))*/@[A-Za-z0-9]+((/.|-)[A-Za-z0-9]+)*/.[A-Za-z0-9]+$/) != -1)
return true;
else
alert("oh");
}
</SCRIPT>
<input type=text onblur=isEmail()>
7. Block keywords (block *** and **** here)
<script language="javascript1.2">
function test() {
if(( ("***") == 0)||( ("****") == 0)){
alert(":)");
();
return false;}
}
</script>
<form name=a onsubmit="return test()">
<input type=text name=b>
<input type="submit" name="Submit" value="check">
</form>
8. Whether the password is the same twice
<FORM METHOD=POST ACTION="">
<input type="password" >
<input type="password" >
<input type="button" value="test" onclick="check()">
</FORM>
<script>
function check()
{
with(){
if(!=)
{
alert("false")
= "";
= "";
}
else [0].submit();
}
}
</script>
Enough :)
Right-blocking is cool
oncontextmenu="return false" ondragstart="return false" onselectstart="return false"
Added in body
two
2.1 The form item cannot be empty
<script language="javascript">
<!--
function CheckForm()
{
if ( == 0) {
alert("Please enter your name!");
();
return false;
}
return true;
}
-->
</script>
2.2 Compare whether the values of two form items are the same
<script language="javascript">
<!--
function CheckForm()
if ( != .PWD_Again.value) {
alert("The password you entered twice is different! Please re-enter.");
();
return false;
}
return true;
}
-->
</script>
2.3 The form item can only be numeric and "_", used for phone/bank account verification, can be extended to domain name registration, etc.
<script language="javascript">
<!--
function isNumber(String)
{
var Letters = "1234567890-"; //You can increase the input value yourself
var i;
var c;
if(( 0 )=='-')
return false;
if( ( - 1 ) == '-' )
return false;
for( i = 0; i < ; i ++ )
{
c = ( i );
if (( c ) < 0)
return false;
}
return true;
}
function CheckForm()
{
if(! isNumber()) {
alert("Your phone number is illegal!");
();
return false;
}
return true;
}
-->
</script>
2.4 Form item input value/length limit
<script language="javascript">
<!--
function CheckForm()
{
if ( > 100 || < 1)
{
alert("The input value cannot be less than zero or greater than 100!");
();
return false;
}
if (<10)
{
alert("Input text is less than 10!");
();
return false;
}
return true;
}
//-->
</script>
2.5 Judgment of 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 is Chinese(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 can't be entered in a limited form item
<script language="javascript">
<!--
function contains(str,charset)// string contains test functions
{
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 an 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;
}
5. Digital format verification
---------------------------------------
//Function name: fucCheckNUM
//Function introduction: Check whether it is a number
//Particle description: Number to check
//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;
}
}
//Explanation legal
return 1;
}
7. A function to determine whether the input is a Chinese language
---------------------------------------
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 visualization 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 one form is detected, if there are multiple forms, the judgment conditions 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;
}
<input onkeyup="value=(/[/W]/g,'') " onbeforepaste="('text',('text').replace(/[^/d]/g,''))" ID="Text1" NAME="Text1">
2. Only numbers can be entered:
<input onkeyup="value=(/[^/d]/g,'') " onbeforepaste="('text',('text').replace(/[^/d]/g,''))" ID="Text2" NAME="Text2">
3. Only input full-width:
<input onkeyup="value=(/[^/uFF00-/uFFFF]/g,'')" onbeforepaste="('text',('text').replace(/[^/uFF00-/uFFFF]/g,''))" ID="Text3" NAME="Text3">
4. Only Chinese characters can be entered:
<input onkeyup="value=(/[^/u4E00-/u9FA5]/g,'')" onbeforepaste="('text',('text').replace(/[^/u4E00-/u9FA5]/g,''))" ID="Text4" NAME="Text4">
--------------------------------------------------------------------------------
Verify illegal characters, sql
function vdf()
{
var i,j,name,value,message,length,type,a=,cb_name;
for (i=0; i<(-2); i+=3)
{
if (a[i].indexOf('#')!=-1)
{
name=fob(a[i].substr(0,a[i].indexOf('#')));
cb_name=fob(a[i].substr((a[i].indexOf('#')+1),a[i].length));
}
else
{
name=fob(a[i]); // Control name
}
message=a[i+1]; // Prompt message
type=a[i+2]; // Type
if (type!="r_time")
{
value=(/ +/g, ""); // control value
}
else
{
value=;
}
}
--------------------------------------------------------------------------------
// =======================================//
if (type=="r_cb")
{
e=(0).elements;
var flag=false;
for (i=0;i<;i++)
{
if (e[i]!=cb_name)
{
if (e[i].checked==true)
{
flag=true;
break;
}
}
if (i==-1)
{
break;
}
}
if (flag==false)
{
alert(message+"!/n"); // A prompt that appears when it is empty
return false;
}
}
// ======================================//
if (type=="r_sl")
{
if (==false)
{
alert(message+"!/n"); // A prompt that appears when it is empty
return false;
}
}
// ========================================//
if (type=="r")
{
if (value=="") // Determine whether it is empty
{
alert(message+"!/n"); // A prompt that appears when it is empty
();
();
return false;
}
}
// ===========================================/
if (type=="o_r")
{
if (value=="") // Determine whether it is empty
{
alert(message+"!/n"); // A prompt that appears when it is empty
return false;
}
}
// ======================================/
if (type=="r_china")
{
if ((/^[/u4e00-/u9fa5]+$/)==-1)
{
alert(message+"!/n"); // It cannot be empty
();
();
return false;
}
}
// ==========================================/
if (type=="r_num_char")
{
if (value=="")
{
alert(message+"!/n"); // A prompt that appears when it is empty
();
();
return false;
}
if ((/^[0-9a-zA-Z]+$/)==-1)
{
alert(message+"!/n"); // A prompt that appears when it is empty
();
();
return false;
}
}
// ========================== When it is not empty, fill in the number ===============//
if (type=="num")
{
if ((/^[0-9]+$/)==-1 && value!="")
{
alert(message+"!/n"); // It cannot be empty
();
();
return false;
}
}
// =========================================//
if (type=="r_num")
{
if (value=="")
{
alert(message+"!/n");
();
();
return false;
}
if ((/^[0-9]+$/)==-1)
{
alert(message+"!/n"); // It cannot be empty
();
();
return false;
}
}
// ======================================//
if (("r_num<")!=-1)
{
length=((('<')+1),); // Get the number after rn<
if (value=="") // Tips for empty
{
alert(message+"!/n");
();
();
return false;
}
If ((/^[0-9]+$/)==-1) // Not a reminder made by numbers
{
alert(message+"!/n");
();
();
return false;
}
If (>length) // Limits to limit the length of numbers
{
alert(message+"!/n");
();
();
return false;
}
}
// =====================================//
if (("r_num>")!=-1)
{
length=(((('>')+1),); // Get the number after rn<
if (value=="") // Tips for empty
{
alert(message+"!/n");
();
();
return false;
}
If ((/^[0-9]+$/)==-1) // Not a reminder made by numbers
{
alert(message+"!/n");
();
();
return false;
}
If (<length) // Limits to limit the length of the number
{
alert(message+"!/n");
();
();
return false;
}
}
// ==================== The number between a-b bits must be entered =================//
if (("r_num#<>")!=-1)
{
length=((('>')+1),);
length=(0,("-"));
length1=(((('-')+1),) // Get the number after rn<
if (value=="") // Tips for empty
{
alert(message+"!/n");
();
();
return false;
}
If ((/^[0-9]+$/)==-1) // Not a reminder made by numbers
{
alert(message+"!/n");
();
();
return false;
}
if (<length || >length1) // Limits to limit the length of the number
{
alert(message+"!/n");
();
();
return false;
}
}
// ======================================//
if (type=="r_float")
{
if (value=="")
{
alert(message+"!/n");
();
();
return false;
}
if ((/^[0-9]+$/)!=-1 || (/^([0-9]+)|([0-9]+/.[0-9]*)|([0-9]*/.[0-9]+)$/)!=-1)
{
return true;
}
else
{
alert(message+"!/n"); // It cannot be empty
();
();
return false;
}
}
// =============================================/
if (("email")!=-1)
{
if (!="")
{
if ((/^[_/.a-z0-9]+@[a-z0-9]+[/.][a-z0-9]{2,}$/i)==-1)
{
alert(message+"!/n");
();
();
return false;
}
}
}
// ==========================================/
if (("r_email")!=-1)
{
if (=="")
{
alert(message+"!/n");
();
();
return false;
}
if ((/^[_/.a-z0-9]+@[a-z0-9]+[/.][a-z0-9]{2,}$/i)==-1)
{
alert(message+"!/n");
();
();
return false;
}
}
// ========================================/
if (type=="r_date")
{
flag=true;
getdate=value;
if ((/^[0-9]{4}-(0[1-9]|[1-9]|1[0-2])-((0[1-9]|[1-9])|1[0-9]|2[0-9]|3[0-1])$/)==-1) // judging the input format is correct
{
flag=false;
}
else
{
var year=(0,('-')) // Get year
// The following operations are obtained by obtaining the month
var transition_month=(0,('-'));
var month=transition_month.substr(transition_month.lastIndexOf('-')+1,transition_month.length);
if (('0')==0)
{
month=(1,);
}
// The following operations get the date
var day=(('-')+1,);
if (('0')==0)
{
day=(1,);
}
//alert(month);
//alert(day)
//return false;
if ((month==4 || month==6 || month==9 || month==11) && (day>30)) // The date of 4,6,9, and November cannot exceed 30
{
flag=false;
}
If (month==2) // Judgment for February
{
if (LeapYear(year))
{
if (day>29 || day<1){ flag=false; }
}
else
{
if (day>28 || day<1){flag=false; }
}
}
else
{
flag=true;
}
}
if (flag==false)
{
alert(message+"!/n"); // A prompt that appears when it is empty
();
();
return false;
}
}
1. Length limit
<script>
function test()
{
if(>50)
{
alert("can't exceed 50 characters!");
();
return false;
}
}
</script>
<form name=a onsubmit="return test()">
<textarea name="b" cols="40" wrap="VIRTUAL" rows="6"></textarea>
<input type="submit" name="Submit" value="check">
</form>
2. It can only be Chinese characters
<input onkeyup="value="/oblog/(/[^/u4E00-/u9FA5]/g,'')">
3." can only be in English
<script language=javascript>
function onlyEng()
{
if(!(>=65&&<=90))
=false;
}
</script>
<input onkeydown="onlyEng();">
4. It can only be a number
<script language=javascript>
function onlyNum()
{
if(!((>=48&&<=57)||(>=96&&<=105)))
//Consider the numeric keys on the keyboard
=false;
}
</script>
<input onkeydown="onlyNum();">
5. Only English characters and numbers
<input onkeyup="value="/oblog/(/[/W]/g,"'') "onbeforepaste="('text',('text').replace(/[^/d]/g,''))">
6. Verify the fuel tank format
<SCRIPT LANGUAGE=javascript RUNAT=Server>
function isEmail(strEmail) {
if ((/^/w+((-/w+)|(/./w+))*/@[A-Za-z0-9]+((/.|-)[A-Za-z0-9]+)*/.[A-Za-z0-9]+$/) != -1)
return true;
else
alert("oh");
}
</SCRIPT>
<input type=text onblur=isEmail()>
7. Block keywords (block *** and **** here)
<script language="javascript1.2">
function test() {
if(( ("***") == 0)||( ("****") == 0)){
alert(":)");
();
return false;}
}
</script>
<form name=a onsubmit="return test()">
<input type=text name=b>
<input type="submit" name="Submit" value="check">
</form>
8. Whether the password is the same twice
<FORM METHOD=POST ACTION="">
<input type="password" >
<input type="password" >
<input type="button" value="test" onclick="check()">
</FORM>
<script>
function check()
{
with(){
if(!=)
{
alert("false")
= "";
= "";
}
else [0].submit();
}
}
</script>
Enough :)
Right-blocking is cool
oncontextmenu="return false" ondragstart="return false" onselectstart="return false"
Added in body
two
2.1 The form item cannot be empty
<script language="javascript">
<!--
function CheckForm()
{
if ( == 0) {
alert("Please enter your name!");
();
return false;
}
return true;
}
-->
</script>
2.2 Compare whether the values of two form items are the same
<script language="javascript">
<!--
function CheckForm()
if ( != .PWD_Again.value) {
alert("The password you entered twice is different! Please re-enter.");
();
return false;
}
return true;
}
-->
</script>
2.3 The form item can only be numeric and "_", used for phone/bank account verification, can be extended to domain name registration, etc.
<script language="javascript">
<!--
function isNumber(String)
{
var Letters = "1234567890-"; //You can increase the input value yourself
var i;
var c;
if(( 0 )=='-')
return false;
if( ( - 1 ) == '-' )
return false;
for( i = 0; i < ; i ++ )
{
c = ( i );
if (( c ) < 0)
return false;
}
return true;
}
function CheckForm()
{
if(! isNumber()) {
alert("Your phone number is illegal!");
();
return false;
}
return true;
}
-->
</script>
2.4 Form item input value/length limit
<script language="javascript">
<!--
function CheckForm()
{
if ( > 100 || < 1)
{
alert("The input value cannot be less than zero or greater than 100!");
();
return false;
}
if (<10)
{
alert("Input text is less than 10!");
();
return false;
}
return true;
}
//-->
</script>
2.5 Judgment of 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 is Chinese(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 can't be entered in a limited form item
<script language="javascript">
<!--
function contains(str,charset)// string contains test functions
{
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 an 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;
}
5. Digital format verification
---------------------------------------
//Function name: fucCheckNUM
//Function introduction: Check whether it is a number
//Particle description: Number to check
//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;
}
}
//Explanation legal
return 1;
}
7. A function to determine whether the input is a Chinese language
---------------------------------------
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 visualization 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()">
Copy the codeThe code is as follows:
function dovalidate()
{
fm=[0] //Only one form is detected, if there are multiple forms, the judgment conditions 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;
}