Form submission Verification

Source: Internet
Author: User
Tags domain name registration to domain

> Shielding function

1.1 shield all keyboard keys
<Script language = "javascript">
<! --
Function document. onkeydown (){
Event. keyCode = 0;
Event. returnvalue = false;
}
-->
</Script>

1.2 Right-click the screen

Add oncontextmenu = self. event. returnvalue = false to the body tag.

Or

<Script language = "javascript">
<! --
Function document. oncontextmenu ()
{
Return false;
}
-->
</Script>

Function nocontextmenu ()
{
If (document. all ){
Event. cancelBubble = true;
Event. returnvalue = false;
Return false;
}
}

Or

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

<Script language = "javascript">
<! --
Function rclick ()
{
If (document. all ){
If (event. button = 2 ){
Event. returnvalue = false;
}
}
}
-->
</Script>


1.3 Block Ctrl + N, Shift + F10, F5 refresh, and return keys

<Script language = "javascript">
<! --
// Shield right-click, Ctrl + N, Shift + F10, F5 refresh, and backspace key
Function window. onhelp () {return false} // block F1 help
Function KeyDown (){
If (window. event. altKey )&&
(Window. event. keyCode = 37) | // mask Alt + direction key seek
(Window. event. keyCode = 39) {// mask Alt + direction key →
Alert ("You are not allowed to use ALT + arrow keys to move forward or backward the webpage! ");
Event. returnvalue = false;
}

/* Note: this does not really block Alt + direction keys,
Because when the Alt + direction key pop-up warning box is displayed, press and hold the Alt key,
With the mouse clicked off the warning box, this blocking method will become invalid. If
Which of the following methods does the master really block the Alt key. */

If (event. keyCode = 8 )&&
(Event. srcElement. type! = "Text "&&
Event. srcElement. type! = "Textarea "&&
Event. srcElement. type! = "Password") | // block the backspace deletion key
(Event. keyCode = 116) | // block the F5 refresh key
(Event. ctrlKey & event. keyCode = 82) {// Ctrl + R
Event. keyCode = 0;
Event. returnvalue = false;
}
If (event. ctrlKey) & (event. keyCode = 78) // block Ctrl + n
Event. returnvalue = false;
If (event. shiftKey) & (event. keyCode = 121) // block shift + F10
Event. returnvalue = false;
If (window. event. srcElement. tagName = "A" & window. event. shiftKey)
Window. event. returnvalue = false; // block shift with the left mouse button to open a new page
If (window. event. altKey) & (window. event. keyCode = 115) {// block Alt + F4
Window. showModelessDialog ("about: blank", "", "dialogWidth: 1px; dialogheight: 1px ");
Return false ;}
}
/* In addition, you can use window. open to shield all IE menus.
Method 1:
Window. open ("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:
Window. open ("Your. asp", "", "fullscreen = yes ")
*/
// -->
</Script>

1.4 shield the browser from the "minimize" "maximize" "Close" key in the upper right corner

<Script language = javascript>
Function window. onbeforeunload ()
{
If (event. clientX> document. body. clientWidth & event. clientY <0 | event. altKey)
{
Window. event. returnvalue = "";
}
}
</Script>

Or open the page in full screen mode.

<Script language = "javascript">
<! --
Window. open (www.32pic.com, "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 to disable the window)

1.5 shield the F5 key

<Script language = "javascript">
<! --
Function document. onkeydown ()
{
If (event. keyCode = 116)
{
Event. keyCode = 0;
Event. cancelBubble = true;
Return false;
}
}
-->
</Script>

1.6 block IE back button

Use <a href = "javascript: location. replace (url)">

1.7 shield the scroll bar of the Main Window

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

1.8 shield the clipboard screen and clear the clipboard continuously

Add onload = "setInterval ('clipboarddata. setData (\ 'text \ ', \') ', 100)" to the body tag )"

1.9 shielding website Printing

<Style>
@ Media print {
* {Display: none}
}
</Style>

1.10 shield the Save icon automatically displayed on IE6.0 Images

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


1.11 shield all scripts on the page

<Noscrrept> </noscript>

<Script language = "javascript">
<! --
Function CheckForm ()
{
If (document. form. name. value. length = 0 ){
Alert ("enter your name! ");
Document. form. name. focus ();
Return false;
}
Return true;
}
-->
</Script>

2.2 compare whether the values of the two form items are the same

<Script language = "javascript">
<! --
Function CheckForm ()
If (document. form. PWD. value! = Document. form. PWD_Again.value ){
Alert ("the password you entered twice is different! Enter again .");
Document. ADDUser. PWD. focus ();
Return false;
}
Return true;
}
-->
</Script>

2.3 form items can only be numbers and "_", used for phone/Bank Account Verification, and can be extended to domain name registration.

<Script language = "javascript">
<! --
Function isNumber (String)
{
Var Letters = "1234567890-"; // you can add input values by yourself.
Var I;
Var c;
If (String. charAt (0) = '-')
Return false;
If (String. charAt (String. length-1) = '-')
Return false;
For (I = 0; I <String. length; I ++)
{
C = String. charAt (I );
If (Letters. indexOf (c) <0)
Return false;
}
Return true;
}
Function CheckForm ()
{
If (! IsNumber (document. form. TEL. value )){
Alert ("your phone number is invalid! ");
Document. form. TEL. focus ();
Return false;
}
Return true;
}
-->
</Script>


2.4 form entry input value/length limit

<Script language = "javascript">
<! --
Function CheckForm ()
{
If (document. form. count. value> 100 | document. form. count. value <1)
{
Alert ("the input value cannot be less than zero or greater than 100! ");
Document. form. count. focus ();
Return false;
}
If (document. form. MESSAGE. value. length <10)
{
Alert ("the input text is less than 10! ");
Document. form. MESSAGE. focus ();
Return false;
}
Return true;
}
// -->
</Script>

2.5 Determination of validity of Chinese/English/numbers/email addresses

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

Function isEnglish (name) // english value detection
{
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) // Chinese value detection
{
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 value detection
{
If (! IsEnglish (name ))
Return false;
I = name. indexOf ("@");
J = name. lastIndexOf ("@");
If (I =-1)
Return false;
If (I! = J)
Return false;
If (I = name. length)
Return false;
Return true;
}

Function isNumber (name) // value detection
{
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 ("your email is invalid! ");
Form. Email. focus ();
Return false;
}
If (! IsEnglish (form. name. value )){
Alert ("the English name is invalid! ");
Form. name. focus ();
Return false;
}
If (! IsChinese (form. cnname. value )){
Alert ("invalid Chinese name! ");
Form. cnname. focus ();
Return false;
}
If (! IsNumber (form. PublicZipCode. value )){
Alert ("the zip code is invalid! ");
Form. PublicZipCode. focus ();
Return false;
}
Return true;
}
// -->
</SCRIPT>

2.6 restrict characters that cannot be entered for Form Items

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

Function contain (str, charset) // string contains the test function
{
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 ("illegal characters entered ");
Document. form. NAME. focus ();
Return false;
}
Return true;
}
// -->
</Script>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.