JS Code judgment collection (Part 2)
<Input type = "button" value = "login" tabindex = "4">
<Input type = "button" value = "register" tabindex = "4">
//////////////////////////////////////// //////
Function trim (inputstr) // place space, before obtaining the form information entered by the client,
Trim is used before submission. For example, "form1.org _ name. value = trim (form1.org _ name. Value );"
{
If (! Inputstr. length> 0) Return "";
VaR starts = 0;
VaR ends = inputstr. length;
While (STARTS <ends)
{
If (inputstr. substring (starts, starts + 1) = "")
Starts ++;
Else
Break;
}
While (STARTS <ends)
{
If (inputstr. substring (ends-1, ends) = "")
Ends --;
Else
Break;
}
Return inputstr. substring (starts, ends );
}
Function isvalidcode (inputs) // verify the zip code
{
VaR I, temp;
VaR isvalidcode = true;
Inputstr = trim (inputs );
If (inputstr. Length = NULL | inputstr. Length = 0 | inputstr. length! = 6) return false;
For (I = 0; I <inputstr. length; I ++)
{
Temp = inputstr. substring (I, I + 1 );
If (! (Temp> = "0" & temp <= "9 "))
{
Isvalidcode = false;
Break;
}
}
Return isvalidcode;
}
Function isvalidtel (inputs) // verify the phone number
{
VaR I, temp;
VaR isvalidtel = true;
Inputstr = trim (inputs );
If (inputstr. Length = NULL | inputstr. Length = 0) return false;
For (I = 0; I <inputstr. length; I ++)
{
Temp = inputstr. substring (I, I + 1 );
If (! (Temp> = "0" & temp <= "9" | temp = "-"))
{
Isvalidtel = false;
Break;
}
}
Return isvalidtel;
}
Function isrealnum (inputs) // check the real number (including the decimal point)
{
VaR I, temp;
VaR isrealnum = true;
Inputstr = trim (inputs );
If (inputstr. Length = NULL | inputstr. Length = 0) return false;
For (I = 0; I <inputstr. length; I ++)
{
Temp = inputstr. substring (I, I + 1 );
If (! (Temp> = "0" & temp <= "9" | temp = "."))
{
Isrealnum = false;
Break;
}
}
Return isrealnum;
}
Function isnumeric (inputs) // check whether integer
{
VaR I, temp;
VaR isnumeric = true;
Inputstr = trim (inputs );
If (inputstr. Length = NULL | inputstr. Length = 0) return false;
// Isvalid = true;
For (I = 0; I <inputstr. length; I ++)
{
Temp = inputstr. substring (I, I + 1 );
If (! (Temp> = "0" & temp <= "9 "))
{
Isnumeric = false;
Break;
}
}
Return isnumeric;
}
Function isvalidide (inputs) // verify the ID card
{
VaR I, temp;
VaR isvalidide = true;
Inputstr = trim (inputs );
If (inputstr. Length = NULL | inputstr. Length = 0 | (inputstr. length! = 15 & inputstr. length! = 18) return false;
For (I = 0; I <inputstr. length; I ++)
{
Temp = inputstr. substring (I, I + 1 );
If (! (Temp> = "0" & temp <= "9") | temp = "X" | temp = "X "))
{
Isvalidide = false;
Break;
}
}
Return isvalidide;
}
Function isvalidname (inputs) // verify account 2 ~ 15 digits (a string consisting of English letters and numbers only)
{
VaR I, temp;
VaR isvalidname = true;
Inputstr = trim (inputs );
If (inputstr. Length = NULL | inputstr. Length = 0 | inputstr. length> 15 | inputstr. Length <2) return false;
For (I = 0; I <inputstr. length; I ++)
{
Temp = inputstr. substring (I, I + 1 );
If (! (Temp> = "0" & temp <= "9") | (temp> = "A" & temp <= "Z ") | (temp> = "A" & temp <= "Z ")))
{
Isvalidname = false;
Break;
}
}
Return isvalidname;
}
Function isvalidphoto (inputs) // verify the photo Extension
{
VaR I, temp;
VaR isvalidphoto = true;
Inputstr = trim (inputs );
If (inputstr. Length = NULL | inputstr. Length = 0) return true; // It is also allowed if no photo is available.
Temp = inputstr. substring (inputstr. lastindexof (".") + 1 );
Temp = temp. tolowercase ();
If (! (Temp = "BMP" | temp = "jpg" | temp = "GIF "))
{
Isvalidphoto = false;
}
Return isvalidphoto;
}
Function isvalidzgh (inputs) // verifies the employee ID with 8 digits (that is, it can only be a string consisting of English letters and numbers)
{
VaR I, temp;
VaR isvalidzgh = true;
Inputstr = trim (inputs );
If (inputstr. Length = NULL | inputstr. Length = 0 | inputstr. length! = 8) return false;
For (I = 0; I <inputstr. length; I ++)
{
Temp = inputstr. substring (I, I + 1 );
If (! (Temp> = "0" & temp <= "9") | (temp> = "A" & temp <= "Z ") | (temp> = "A" & temp <= "Z ")))
{
Isvalidzgh = false;
Break;
}
}
Return isvalidzgh;
}
Function isvalidxh (inputs) // check student ID 7 (that is, it can only be a string consisting of English letters and numbers)
{
VaR I, temp;
VaR isvalidxh = true;
Inputstr = trim (inputs );
If (inputstr. Length = NULL | inputstr. Length = 0 | inputstr. length! = 7) return false;
For (I = 0; I <inputstr. length; I ++)
{
Temp = inputstr. substring (I, I + 1 );
If (! (Temp> = "0" & temp <= "9") | (temp> = "A" & temp <= "Z ") | (temp> = "A" & temp <= "Z ")))
{
Isvalidxh = false;
Break;
}
}
Return isvalidxh;
}
Function isvalidkcid (inputs) // check the course number by five digits (that is, a string consisting of only digits)
{
VaR I, temp;
VaR isvalidkcid = true;
Inputstr = trim (inputs );
If (inputstr. Length = NULL | inputstr. Length = 0 | inputstr. length! = 5) return false;
For (I = 0; I <inputstr. length; I ++)
{
Temp = inputstr. substring (I, I + 1 );
If (! (Temp> = "0" & temp <= "9 "))
{
Isvalidkcid = false;
Break;
}
}
Return isvalidkcid;
}
Function isvalidnamee (inputs) // verify account 4 ~ 20 digits (a string consisting of English letters and numbers only)
{
VaR I, temp;
VaR isvalidname = true;
Inputstr = trim (inputs );
If (inputstr. Length = NULL | inputstr. Length = 0 | inputstr. length> 20 | inputstr. Length <4) return false;
For (I = 0; I <inputstr. length; I ++)
{
Temp = inputstr. substring (I, I + 1 );
If (! (Temp> = "0" & temp <= "9") | (temp> = "A" & temp <= "Z ") | (temp> = "A" & temp <= "Z ")))
{
Isvalidname = false;
Break;
}
}
Return isvalidname;
}
======================================
<Script language = "JavaScript">
Function login ()
{
Form1.uname. value = trim (form1.uname. value );
Form1.pwd. value = trim (form1.pwd. value );
Form1.pwd2. value = trim (form1.pwd2. value );
Form1.email. value = trim (form1.email. value );
Form1.nc. value = trim (form1.nc. value );
If (! Isvalidname (form1.uname. Value ))
{
Alert ("Please note: the user name must be" 2 ~ 15 digits in English 』! ");
Form1.uname. Focus ();
Return false;
}
Else if (! Isvalidname (form1.pwd. Value ))
{
Alert ("Please note: the password must be" 2 ~ 15 digits in English 』! ");
Form1.pwd. Focus ();
Return false;
}
Else if (! Isvalidname (form1.pwd2. Value ))
{
Alert ("Please note: the password must also be" 2 ~ 15 digits in English 』! ");
Form1.pwd2. Focus ();
Return false;
}
Else if (form1.pwd. value! = Form1.pwd2. value)
{
Alert ("the two passwords are inconsistent! ");
Form1.pwd. Focus ();
Return false;
}
Else if (form1.email. value = "" | form1.email. value. length> 100)
{
Alert ("enter an email! ");
Form1.email. Focus ();
Return false;
}
Else if (form1.nc. value = "" | form1.nc. value. length> 15)
{
Alert ("enter a nickname! ");
Form1.nc. Focus ();
Return false;
}
Else if (window. Confirm ("You are sure to submit! "))
Return true;
Else
Return false;
}
Function Regedit ()
{
VaR litop = (screen. Height-162)/2;
VaR lileft = (screen. Width-360)/2;
Window. Open ("/Regedit. aspx", "Reg", "titlebar = No, fullscreen = No, dependent = Yes, Height = 162, width = 360,
Top = "+ litop +", Left = "+ lileft + ",
Toolbar = No, menubar = No, scrollbars = No, resizable = No,
Channelmode = No, status = No, location = No, directories = No ");
}
</SCRIPT>
1. Copy disabled. Right-click Disabled!
<SCRIPT>
// Add page Protection
Function RF ()
{Return false ;}
Document. oncontextmenu = RF
Function keydown ()
{If (event. ctrlkey = true | event. keycode = 93 | event. shiftkey = true) {return false ;}}
Document. onkeydown = keydown
Function drag ()
{Return false ;}
Document. ondragstart = drag
Function stopmouse (e ){
If (navigator. appname = 'netscape '& (E. Which = 3 | E. Which = 2 ))
Return false;
Else if
(Navigator. appname = 'Microsoft Internet Explorer '& (event. Button = 2 | event. Button = 3 )){
Alert ("no copyright, but do not copy it :)");
Return false;
}
Return true;
}
Document. onmousedown = stopmouse;
If (document. layers)
Window. captureevents (event. mousedown );
Window. onmousedown = stopmouse;
</SCRIPT>
<Script language = "JavaScript">
Function jm_cc (OB ){
VaR OBJ = mm_findobj (OB); If (OBJ ){
Obj.select({%js%obj.createtextrange(%%%js.exe ccommand ("copy ");}
}
Function mm_findobj (n, d) {// v4.0
VaR P, I, X; If (! D) d = document; if (P = n. indexof ("? ")> 0 & parent. frames. Length ){
D=parent.frames[n.substring(p%1%].doc ument; n = n. substring (0, P );}
If (! (X = d [N]) & D. All) x = D. All [N]; for (I = 0 ;! X & I <D. Forms. length; I ++) x = D. Forms[N];
For (I = 0 ;! X & D. Layers & I <D. layers. length; I ++) xw.mm_findobj(n,d.layers.doc ument );
If (! X & document. getelementbyid) x = Document. getelementbyid (n); Return X;
}
</SCRIPT>
2. Conversion between JS and HTML ~~~~~~~~~
<Body>
<Style>
Body {font-size: 9pt}
Textarea {color = "#707888"; font-family: "verdana "}
. Inputs {color = "#707888"; Border: 1px solid; Background: # f4f4f4}
</Style>
Enter the format you want to convert, either JavaScript or DHTML.
<Br>
<Textarea id = "codes" style = "width: 730; Height: 300">
</Textarea>
<Br>
<Button class = "inputs">
Clear output
</Button>
<Button class = "inputs">
Select all codes
</Button>
<Button class = "inputs">
Copy code
</Button>
<Button class = "inputs">
Paste code
</Button>
<Button class = "inputs">
Convert js to HTML
</Button>
<Button class = "inputs">
Convert HTML to JS
</Button>
<Button class = "inputs">
Click Show source file
</Button>
<Button class = "inputs">
Preview code [F12]
</Button>
<Br>
This is the output format window:
<Br>
<Textarea id = "outputs" style = "width: 730; Height: 300"> </textarea>
<Br>
A bad message: the JavaScript-to-HTML part only supports
<Br>
Author: flashsoft2000 QQ: 14433548
<Input id = "hide" style = 'display: none'>
<SCRIPT>
// Define the title
Document. Title = "multi-function webpage conversion"
// Display the webpage source file
Function writes ()
{
Outputs. value = Document. Body. outerhtml;
}
// Clear the Output Window
Function clears ()
{
Outputs. innerhtml = '';
}
// Replace a specified character
// N1 string, N2 to be replaced, N3 to be replaced
Function commute (N1, N2, N3)
{
VaR A1, A2, A3 = 0, a0 =''
A1 = n1.length;
A2 = n2.length;
For (x = 0; x <= (a1-a2); X ++)
{
If (n1.substr (x, A2) = n2)
{
A0 + = n1.substring (A3, X );
A0 + = N3;
X + = (a2-1 );
A3 = x + 1;
}
}
If (A3 <A1) A0 + = n1.substring (A3, A1)
{
Return A0;
}
}
// Convert JavaScript to DHTML
Function js2html ()
{
Hide. value = codes. Value
Hide. value = commute (hide. value ,'"""','"');
Hide. value = commute (hide. Value, 'document. Write ("','');
Hide. value = commute (hide. value ,'")','');
Hide. value = commute (hide. value, '<SCRIPT> ','');
Hide. value = commute (hide. value, '<"/SCRIPT> ','');
Outputs. value = hide. Value
}
// Convert DHTML to Javascript
Function html2js ()
{
Hide. value = codes. Value
Hide. value = commute (hide. value ,'"','"""');
Hide. value = commute (hide. value ,'""','""""');
Hide. value = commute (hide. value, '<"/SCRIPT>', '<"/SCRIPT> ');
Outputs. value = "<SCRIPT> document. Write (" + hide. Value + ") <"/SCRIPT>"
}
// Preview the code
Function seehtm ()
{
Open().doc ument. Write ("<title> test code window </title>" + outputs. value );
}
// Preview with the shortcut key F12
Document. onkeydown = seehtms
Function seehtms ()
{
If (event. keycode = 123 ))
{
Open().doc ument. Write ("<title> test code window </title>" + outputs. value );
}
}
// Select all codes
Function TA ()
{
Outputs. Select ()
}
// Copy the code
Function Tc ()
{
Document.exe ccommand ("copy ")
}
// Paste the code
Function TP ()
{
Outputs. Focus ()
Document.exe ccommand ("Paste ")
}
</SCRIPT>
Link: http://www.cnblogs.com/koolay/articles/984852.html