SoFunction
Updated on 2025-02-28

Form Submission Verification Class

>Shielding function category

1.1 Block all keys on the keyboard
<script language="javascript">
<!--
function (){
    = 0;
    = false;
}
-->
</script>

1.2 Block the right mouse button

Add oncontextmenu==false to the body tag

or

<script language="javascript">
<!--
function () 

  return false; 

-->
</script>

function nocontextmenu()

    if() {
        =true;
        =false; 
        return false; 
    }
}

or

<body onmousedown="rclick()" oncontextmenu= "nocontextmenu()">

<script language="javascript">
<!--
function rclick()
{
    if() {
        if ( == 2){
            =false;
        }
    }
}
-->
</script>


1.3 Block Ctrl+N, Shift+F10, F5 refresh, backspace key

<script language="javascript">
<!--
//Mask the right mouse button, Ctrl+N, Shift+F10, F5 refresh, backspace key
function (){return false} //Block F1 help
function KeyDown(){
  if (()&&
((==37)||//Shield Alt+ Arrow Key ←
(==39))){  //Shield Alt+ Arrow keys →
alert("You are not allowed to use the ALT+ arrow keys to advance or back the web page!");
     =false;
     }

/* Note: This is not really blocking the Alt+ arrow keys,
Because when the Alt+ arrow key pops up the warning box, press and hold the Alt key and keep it from putting it.
Click the warning box with the mouse, and this blocking method will fail. If
Any expert has a way to truly block the Alt key, please let me know. */

  if (( == 8) && 
      ( != "text" && 
       != "textarea" && 
!= “password”) ||           //Shield backspace deletion key
(==116)||
      ( && ==82)){            //Ctrl + R
     =0;
     =false;
     }
if (()&&(==78))   //Shield Ctrl+n
     =false;
if (()&&(==121))//Shield shift+F10
     =false;
  if ( == "A" && ) 
= false;  //Shift add the left mouse button to open a new web page
if (()&&(==115)){ //Block Alt+F4
      ("about:blank","","dialogWidth:1px;dialogheight:1px");
      return false;}
  }
/* In addition, you can use the method of blocking all menus of IE
The first method:
("Your.htm","","toolbar=no,location=no,directories=no,menubar=no,scrollbars=no,resizable=yes,status=no,top=0,left=0")
The second method is to open a full-screen page:
("Your.asp","","fullscreen=yes")
 */
//-->
</script>

1.4 Block the "minimize", "maximize" and "close" keys in the upper right corner of the browser

<script language=javascript>
function ()
{
  if(>&&<0||)
  {
     = "";
  }
}
</script>

Or use full screen to open the page

<script language="javascript">
<!--
(,"32pic","fullscreen=3,height=100, width=400, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no");
-->
</script>

Note: Add onbeforeunload="javascript:return false" to the body tag (make it impossible to close the window)

1.5 shielded F5 key

<script language="javascript">
<!--
function () 

    if ( ==116) 
    { 
         = 0; 
         = true; 
        return false; 
    }
}
-->
</script>

1.6 Block IE Back Button

Use <a href="javascript:(url)"> when you link

1.7 Block the main window scrollbar

Add style="overflow-y:hidden" to the body tag

1.8 Block the screen and continuously clear the clipboard

Add onload="setInterval('(\'Text\',\'\')',100)"

1.9 Printing function of blocking websites

<style>
@media print {
   * { display: none }
}
</style>

1.10 Block IE6.0 Save icons that appear automatically on pictures

Method 1:
<META HTTP-EQUIV="imagetoolbar" CONTENT="no">
Method 2:
<img galleryimg="no">

1.11 Block all scripts in the page

<noscrript></noscript>

<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 number 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 The input value/length limit of form items

<script language="javascript">
<!--
function CheckForm() 
{
    if ( > 100 ||  < 1)
{
alert("The input value cannot be less than zero and greater than 100!");
 ();
 return false;
}
    if (<10)
{
alert("Input text is less than 10!");
 ();
 return false;
}
return true;
}
//-->
</script>

2.5 Judgment 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 = ("@");
 j = ("@");
 if(i == -1)
  return false;
 if(i != j)
  return false;
 if(i == )
  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("The postal 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>