JavaScript technology often used in B/s development

Source: Internet
Author: User
Tags date format empty getdate include sql version window
JavaScript

First, the Verification class
1, digital verification within
1.1 Integers
1.2 Integers greater than 0 (validation of ID to be transmitted)
1.3 Validation of negative integers
1.4 integers cannot be larger than IMAX
1.5 integers cannot be less than imin
2, Time Class
2.1 Short time, form (13:04:06)
2.2 Short Date, form (2003-12-05)
2.3 Long time, shaped like (2003-12-05 13:04:06)
2.4 is a month and a half. Form (2003-05, or 2003-5)
2.5 hours and minutes, shaped like (12:03)
3, Form category
3.1 The values of all forms cannot be empty
The value of the 3.2 multiline text box cannot be null.
3.3 Multiple-line text boxes cannot have values greater than Smaxstrleng
3.4 Multiline text box cannot have a value less than Smixstrleng
3.5 Determine if the radio box is selected.
3.6 Determine if the check box is selected.
3.7 check box selection, multiple selection, all do not select, reverse election
3.8 file types in the process of uploading files
4. Character class
4.1 Judging characters are all made up of a A-Z or a-Z letter.
4.2 Judging characters consist of letters and numbers.
4.3 Judging characters consist of letters and numbers, underscores, and dots. And the beginning can only be underlined and letters.
4.4 String substitution function. Replace ();
5. Browser class
5.1 Determining the type of browser
5.2 To determine IE version
5.3 Determine the resolution of the client

6. Combined class
6.1 Email's judgment.
6.2 Verification of mobile phone number
6.3 Authentication of the ID card

Second, functional category

1, time and related control classes
1.1 Calendar
1.2 Time Control
13,000 calendar
1.4 Displaying the dynamic display of clock effects (text, such as OA time)
1.5 Display dynamic clock effects (images, like watches)
2, Form category
2.1 Automatically generate a form
2.2 Dynamically add, modify, delete the elements in the dropdown box
2.3 Drop down box to enter the content
Only IMAX text can be entered in more than 2.4 lines of text boxes. If more input, automatically reduce to IMAX text (more for SMS send)

3, Printing class
3.1 Print controls
4. Event class
4.1 Shielding right Button
4.2 Screen all function keys
4.3--> and <--F5 f11,f9,f1
4.4 Shielded key combination CTRL + N
5, Web design class
5.1 Continuous scrolling text, picture (note is continuous, two paragraphs of text and the picture does not appear blank)
5.2 HTML Edit Control class
5.3 Color Selection Box control
5.4 Drop down menu
5.5 Drop-down menu with two or more layers
5.6 Copy IE menu button. (Effect such as rongshuxa.com navigation column)
5.7 status bar, title bar dynamic effect (a lot of examples, you can study)
5.8 Double click, Web page Auto Roll screen
6. Tree-type structure.
6.1 Asp+sql Edition
6.2 Asp+xml+sql Edition
6.3 Java+sql or Java+sql+xml.
7, no border effect of the production
8. Continuous pull down frame technology
9, text sorting




One, verification class


1, digital authentication internal


1.1 Integer


/^ (-|\+) \d+$/.test (str)


1.2 is greater than 0 integer (for the validation of the ID that came from)


/^\d+$/.test (str)

Verification of
1.3 negative integers


/^-\d+$/.test (str)


2, Time class


2.1 short time, shaped like (13:04:06)


function Istime (str)


      {


var a = Str.match (/^ (\d{1,2}) (:)? \d{1,2}) \2 (\d{1,2}) $/);


if (a = = null) {alert (' input parameter is not a time format '); return false;}


if (a[1]&gt;24 | | a[3]&gt;60 | | a[4]&gt;60)


        {


alert ("Time format is not");


return False


        }


return true;


      }


2.2 Short date, shaped like (2003-12-05)


function Strdatetime (str)


      {


var r = Str.match (/^ (\d{1,4}) (-|\/) (\d{1,2}) \2 (\d{1,2});


if (r==null) return false;


var d= new Date (r[1], r[3]-1, r[4]);


return (D.getfullyear () ==r[1]&amp;&amp; (D.getmonth () +1) ==r[3]&amp;&amp;d.getdate () ==r[4]);


      }


2.3 Long time, shaped like (2003-12-05 13:04:06)


function Strdatetime (str)


      {


var reg =/^ (\d{1,4}) (-|\/) (\d{1,2}) \2 (\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2}) $/;


var r = Str.match (reg);


if (r==null) return false;


var d= new Date (r[1], r[3]-1,r[4],r[5],r[6],r[7]);


return (D.getfullyear () ==r[1]&amp;&amp; (D.getmonth () +1) ==r[3]&amp;&amp;d.getdate () ==r[4]&amp;&amp; D.gethours () ==r[5]&amp;&amp;d.getminutes () ==r[6]&amp;&amp;d.getseconds () ==r[7]);


      }


2.4 of the annual and monthly. Form (2003-05, or 2003-5)


2.5 only have hours and minutes, shaped like (12:03)


3, Form class


3.1 All of the form's values cannot be empty


&lt;input onblur= "if (This.value.replace (/^\s+|\s+$/g, ') = =") alert (' cannot be empty! ') " &gt;

The value of the
3.2 multiline text box cannot be null.

The value of the
3.3 multiline text box cannot exceed Smaxstrleng

The value of the
3.4 multiline text box cannot be less than Smixstrleng


3.5 To determine if the radio box is selected.


3.6 Determines whether the check box is selected.


3.7 check box selection, multiple selection, all do not select, the reverse selection


3.8 File Type in the process of uploading files


4, character class


4.1 Judgment characters are all made up of a-Z or a-Z


&lt;input onblur= "if (/[^a-za-z]/g.test (this.value)) alert (' Error ')" &gt;

The
4.2 judgment character consists of letters and numbers.


&lt;input onblur= "if (/[^0-9a-za-z]/g.test (this.value)) alert (' Error ')" &gt;


4.3 determines that characters consist of letters and numbers, underscores, and dots. And the beginning can only be underlined and the letter


/^ ([A-za-z_]{1}) ([\w]*) $/g.test (str)


4.4 string substitution function. Replace ();


5, Browser class


5.1 To determine the type of browser


Window.navigator.appName


5.2 To determine the version of IE


window.navigator.appVersion


5.3 To determine the resolution of the client


Window.screen.height; Window.screen.width;


 


6, combined class


6.1 Email's judgment.


function Ismail (mail)


      {


return (REGEXP) (/^\w+ (-\w+) | ( \.\w+)) *\@[a-za-z0-9]+ (\.| -) [a-za-z0-9]+) *\. [a-za-z0-9]+$/). Test (mail);


      }


6.2 Mobile phone number verification

Verification of
6.3 ID card


function Isidcardno (num)


      {


if (isNaN (num)) {alert ("input is not a number!") "); return false;}


var len = num.length, re;


if (len = 15)


re = new RegExp (/^ (\d{6}) ()? ( \D{2}) (\d{2}) (\d{2}) (\d{3}) $/);


else if (len = 18)


re = new RegExp (/^ (\d{6}) ()? ( \D{4}) (\d{2}) (\d{2}) (\d{3}) (\d) $/);


Else {alert ("The number of digits entered is not correct!") "); return false;}


var a = Num.match (re);


if (a!= null)


        {


if (len==15)


          {


var D = new Date ("+a[3]+"/"+a[4]+"/"+a[5");


var B = d.getyear () ==a[3]&amp;&amp; (D.getmonth () +1) ==a[4]&amp;&amp;d.getdate () ==a[5];


          }


Else


          {


var D = new Date (a[3]+ "/" +a[4]+ "/" +a[5]);


var B = d.getfullyear () ==a[3]&amp;&amp; (D.getmonth () +1) ==a[4]&amp;&amp;d.getdate () ==a[5];


          }


if (! B) {alert ("Enter the ID number" + a[0] + "in the wrong birth date!" "); return false;}


        }


return true;


      }

3.7 check box selection, multiple selection, all do not select, reverse election
<form name=hrong>
<input Type=checkbox name=all > Full Selection <br/>
<input Type=checkbox name=mm ><br/>
<input Type=checkbox name=mm ><br/>
<input Type=checkbox name=mm ><br/>
<input Type=checkbox name=mm ><br/>
<input Type=checkbox name=mm ><br/><br/>


<input Type=checkbox name=all2 > Full Selection <br/>
<input Type=checkbox name=mm2 ><br/>
<input Type=checkbox name=mm2 ><br/>
<input Type=checkbox name=mm2 ><br/>
<input Type=checkbox name=mm2 ><br/>
<input Type=checkbox name=mm2 ><br/>

</form>

<script language= "JavaScript" >
function Checkall (str)
{
var a = document.getelementsbyname (str);
var n = a.length;
for (var i=0; i<n; i++)
a[i].checked = window.event.srcElement.checked;
}
function Checkitem (str)
{
var e = window.event.srcElement;
var all = eval ("Document.hrong." + str);
if (e.checked)
{
var a = Document.getelementsbyname (e.name);
All.checked = true;
for (var i=0; i<a.length; i++)
{
if (!a[i].checked) {all.checked = false; break;}
}
}
else all.checked = false;
}
</SCRIPT>

3.8 file types in the process of uploading files
<input type=file >

Paint:
<object
id=s
style= "left:0px; width:392px; top:0px; height:240px "
height=240
width=392
classid=" Clsid:369303c2-d7ac-11d0-89d5-00a0c90833e6 "
</ Object>
<script>
S.drawingsurface.arcdegrees (0,0,0,30,50,60);
S.drawingsurface.arcradians (30,0,0,30,50,60);
S.drawingsurface.line (10,10,100,100);
</script>

Write registry:
<script>
var WshShell = WScript.CreateObject ("Wscript.Shell");
WshShell.RegWrite ("hkcu\\software\\acme\\fortuneteller\\", 1, "reg_binary");
WshShell.RegWrite ("Hkcu\\software\\acme\\fortuneteller\\mindreader", "goocher!", "REG_SZ");
var bkey =    wshshell.regread ("hkcu\\software\\acme\\fortuneteller\\");
WScript.Echo (WshShell.RegRead ("Hkcu\\software\\acme\\fortuneteller\\mindreader"));
Wshshell.regdelete ("Hkcu\\software\\acme\\fortuneteller\\mindreader");
Wshshell.regdelete ("hkcu\\software\\acme\\fortuneteller\\");
Wshshell.regdelete ("hkcu\\software\\acme\\");
</script>

Tablae related (client dynamically increasing rows)
<script language= "JScript"
Function Numbercells () {
     var count=0;
    for (i=0 i < document.all.mytable.rows.length; i++) {
         for (J=0 J < document.all.mytable.rows (i) cells.length; j + +) {
             document.all.mytable.rows (i). Cells (j). innertext = count;
            count++;
       }
   }
}
</script>
<body
<table id=mytable border=1>
<TR><TH> </TH> <TH> </TH><TH> </TH><TH> </th></tr>
<TR><TD> </TD> <TD> </TD><TD> </TD><TD> </td></tr>
<TR><TD> </TD> <TD> </TD><TD> </td><td&Gt </td></tr>
</table>
</body>
</HTML>

1. Identity card Strict authentication:

<script>
var acity={11: "Beijing", 12: "Tianjin", 13: "Hebei", 14: "Shanxi", 15: "Inner Mongolia", 21: "Liaoning", 22: "Jilin", 23: "Heilongjiang", 31: "Shanghai", 32: " Jiangsu ", 33:" Zhejiang ", 34:" Anhui ", 35:" Fujian ", 36:" Jiangxi ", 37:" Shandong ", 41:" Henan ", 42:" Hubei ", 43:" Hunan ", 44:" Guangdong ", 45:" Guangxi ", 46:" Hainan ", 50:" Chongqing ", 51:" Sichuan ", 52 : "Guizhou", 53: "Yunnan", 54: "Tibet", 61: "Shaanxi", 62: "Gansu", 63: "Qinghai", 64: "Ningxia", 65: "Xinjiang", 71: "Taiwan", 81: "Hong Kong", 82: "Macao", 91: "Foreign"}
 
function Cidinfo (SID) {
 var isum=0
 var info= ""
 if (!/^\d{17} (\d|x) $/i.test (SID)) return False
 sid=sid.replace (/x$/i, "a");
 if (Acity[parseint (Sid.substr (0,2))]==null) return "Error: illegal area";
 sbirthday=sid.substr (6,4) + "-" +number (Sid.substr (10,2)) + "-" +number (Sid.substr (12,2));
 var d=new Date (Sbirthday.replace (/-/g, "/")
 if (sbirthday!= (d.getfullyear () + "-" + (D.getmonth () + 1) + "-" + d.getdate ()) return "Error: illegal Birthday";
 for (var i = 17;i>=0;i-) Isum + = (Math.pow (2,i)%) * parseint (Sid.charat (17-i), one)
 if (isum%11! =1) return "ERROR: illegal license Number";
 return Acity[parseint (Sid.substr (0,2))]+ "," +sbirthday+ "," + (SID.SUBSTR (16,1)%2? " Male ":" female ")
}

document.write (Cidinfo ("380524198002300016"), "<br/>");
document.write (Cidinfo ("340524198002300019"), "<br/>")
document.write (Cidinfo ("340524197711111111"), "<br/>")
document.write (Cidinfo ("34052419800101001x"), "<br/>");
</script>

2. Verifying IP addresses
<script language= "JavaScript" >
function Isip (s) {
var check=function (v) {Try{return (v<=255 && v>=0)}catch (x) {return false}};
var re=s.split (".")
Return (re.length==4)? (check (re[0]) && check (re[1]) && check (re[2)) && Check (re[3)): false
}

var s= "202.197.78.129";
Alert (Isip (s))
</SCRIPT>

3. Add SP1 to use the borderless window!!
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<ie:download id= "include" style= "Behavior:url (#default #download)"/>
<title>chromeless window</title>

<script language= "JScript" >
/*---Special for andot---* *

/*
This following code are designed and writen by Windy_sk <seasonx@163.net>
can use it freely, but u must held all the copyright items!
*/

/*---for ANDOT Again---* *

var cw_width = 400;
var cw_height = 300;
var cw_top = 100;
var cw_left = 100;
var cw_url = "/";
var NEW_CW = Window.createpopup ();
var cw_body = New_CW.document.body;
var content = "";
var csstext = "Margin:1px;color:black;" border:2px outset;border-style:expression (Onmouseout=onmouseup=function () {this.style.borderstyle= ' outset '}, Onmousedown=function () {if (event.button!=2) this.style.borderstyle= ' inset '}); background-color:buttonface;width : 16px;height:14px;font-size:12px;line-height:11px;cursor:default; ";

Build Window
Include.startdownload (Cw_url, function (source) {content=source});

Function insert_content () {
 var temp = "";
 CW_Body.style.overflow  = "hidden";
 cw_body.style.backgroundcolor = "white";
 CW_Body.style.border  =  "solid black 1px";
 content = Content.replace (/<a ([^>]*) >/g, "<a $1>");
 temp + = "<table width=100% height=100% cellpadding=0 cellspacing=0";
 temp + = "<tr style="; Font-size:12px;background: #0099CC; Height:20;cursor:default ' ondblclick=\ ' max.innertext=max.innertext== ' 1 '? ' 2 ': ' 1 ';p arent.if_max=!parent.if_max;parent.show_cw (); \ ">";
 temp + + <td style= ' color: #ffffff;p adding-left:5px ' >chromeless window for IE6 sp1</td> ';
 temp + + <td style= ' color: #ffffff;p adding-right:5px; ' align=right> ';
 temp = "<span id=help  onclick=\" alert (' chromeless Window for IE6 sp1 -  Ver 1.0\\n\\ncode B Y windy_sk\\n\\nspecial for Andot ') \ "style=\" "+csstext+" Font-family:system;padding-righT:2px;\ ">?</span>";
 temp = "<span id=min   style=\" "+csstext+" font-family:webdings;\ "title= ' Minimum ' >0</" Span> ";
 temp = "<span id=max   onclick=\" this.innertext=this.innertext== ' 1 '? 2 ': ' 1 ';p arent.if_max=!parent.if_max;parent.show_cw (); \ "Style=\" "+csstext+" font-family:webdings;\ "title=" Maximum ' >1</span> ';
 temp = "<span id=close style=\" "+csstext+" font-family:system;padding-right:2px;\ "title= ' Close ' >x </span> ";
 temp + = "</td></tr><tr><td colspan=2>";
 temp + = "<div id=include style= ' Overflow:scroll;overflow-x:hidden;overflow-y:auto; height:100%; Width: "+cw_width+" ' > ';
 temp + = content;
 temp + = "</div>";
 temp + = "</td></tr></table>";
 cw_body.innerhtml = temp;
}

SetTimeout ("Insert_content ()", 1000);

var If_max = true;
function SHOW_CW () {
Window.moveto (10000, 10000);
if (If_max) {
New_cw.show (Cw_top, Cw_left, Cw_width, cw_height);
if (typeof (New_CW.document.all.include)!= "undefined") {
New_CW.document.all.include.style.width = Cw_width;
New_CW.document.all.Max.innerText = "1";
}

}else{
New_cw.show (0, 0, screen.width, screen.height);
New_CW.document.all.include.style.width = Screen.width;
}
}

Window.onfocus = SHOW_CW;
Window.onresize = SHOW_CW;

Move Window
var drag_x,drag_y,draging=false

function Drag_move (e) {
if (draging) {
New_cw.show (e.screenx-drag_x, e.screeny-drag_y, Cw_width, cw_height);
return false;
}
}

function Drag_down (e) {
if (e.button==2) return;
if (new_cw.document.body.offsetwidth==screen.width && new_cw.document.body.offsetheight==screen.height) Return
Drag_x=e.clientx;
Drag_y=e.clienty;
Draging=true;
E.srcelement.setcapture ();
}

function Drag_up (e) {
Draging=false;
E.srcelement.releasecapture ();
if (new_cw.document.body.offsetwidth==screen.width && new_cw.document.body.offsetheight==screen.height) Return
Cw_top = e.screenx-drag_x;
Cw_left = e.screeny-drag_y;
}

</SCRIPT>
</HTML>

Verification of phone numbers

Requirements:
(1) The telephone number shall consist of numbers, "(") "and"-"
(2) Phone number is 3 to 8 digits
(3) If the phone number contains an area code, then the area code is three digits or four digits
(4) The area code is separated by "(", ")" or "-" and other parts
(5) Mobile phone number is 11 or 12 digits, if 12 digits, then the first digit is 0
(6) The first and second digits of the 11-digit mobile phone number are "13"
(7) The second and third digits of the 12-digit mobile phone number are "13"
According to these rules, you can go with the following regular expressions:
(^[0-9]{3,4}\-[0-9]{3,8}$) | (^[0-9]{3,8}$) | (^\ ([0-9]{3,4}\) [0-9]{3,8}$) | (^0{0,1}13[0-9]{9}$)


<script language= "JavaScript" >
function Phonecheck (s) {
var str=s;
var reg=/(^[0-9]{3,4}\-[0-9]{3,8}$) | (^[0-9]{3,8}$) | (^\ ([0-9]{3,4}\) [0-9]{3,8}$) | (^0{0,1}13[0-9]{9}$)/
Alert (Reg.test (str));
}
</script>
<input type=text name= "iphone" >
<input Type=button value= "Check" >

Has the effect of not echoing the input non-numeric character, that is, not reacting to the input of a non-numeric character.
function Numbersonly (field,event) {
var Key,keychar;
if (window.event) {
key = Window.event.keyCode;
}
else if (event) {
key = Event.which;
}
else{
return True
}
Keychar = String.fromCharCode (key);
if ((key = null) | | (key = = 0) | | (key = = 8) | | (key = = 9) | | (key = = 13) | | (key = = 27)) {
return true;
}
else if (("0123456789."). IndexOf (Keychar) >-1) {
Window.status = "";
return true;
}
else {
Window.status = "Field excepts numbers only";
return false;
}
}

Verifying IP

Str=document. RegExpDemo.txtIP.value;
if (/^ (\d{1,3}) \. ( \d{1,3}) \. (\d{1,3}) \. (\d{1,3}) $/.test (str) ==false)
{
Window.alert (' Wrong IP address format ');
Document. RegExpDemo.txtIP.select ();
Document. RegExpDemo.txtIP.focus ();
Return
}
if (regexp.$1<1 | | regexp.$1>254| | regexp.$2<0| | regexp.$2>254| | regexp.$3<0| | regexp.$3>254| | regexp.$4<1| | regexp.$4>254)
{
Window.alert (' Wrong IP address ');
Document. RegExpDemo.txtIP.select ();
Document. RegExpDemo.txtIP.focus ();
Return
}
Culling the 0 of the front like 010.020.020.03
var str=str.replace (/0 (\d)/g, "$");
Str=str.replace (/0 (\d)/g, "$");
Window.alert (str);







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.