JavaScript Common validation functions

Source: Internet
Author: User
Tags date format empty functions getdate include sql window
javascript| function

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
10, drawing category, including cake, column, vector, the beta-Aids curve
11, manipulating the Client registry class
12,div Layer Related (drag, show, hide, move, increase)
13,tablae related (client dynamic increase ranks, simulation progress bar, scrolling list, etc.)
14, various <object classid=> related classes, such as player, flash and script interaction, etc.
16, refresh/Simulate no refresh asynchronous invocation class (XMLHTTP or Iframe,frame)


First, the Verification class
1, digital verification within
1.1 Integers
/^ (-|\+) \d+$/.test (str)
1.2 Integers greater than 0 (validation of ID to be transmitted)
/^\d+$/.test (str)
1.3 Validation of negative integers
/^-\d+$/.test (str)
2, Time Class
2.1 Short time, form (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]>24 | | a[3]>60 | | a[4]>60)
{
Alert ("Time format is not");
return False
}
return true;
}
2.2 Short Date, form (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]&& (D.getmonth () +1) ==r[3]&&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]&& (D.getmonth () +1) ==r[3]&&d.getdate () ==r[4]&&d.gethours () = =r[5]&&d.getminutes () ==r[6]&&d.getseconds () ==r[7]);
}
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
<input onblur= "if (This.value.replace (/^\s+|\s+$/g, ') = =") alert (' 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.
<input onblur= "if (/[^a-za-z]/g.test (this.value)) alert (' Error ')" >
4.2 Judging characters consist of letters and numbers.
<input onblur= "if (/[^0-9a-za-z]/g.test (this.value)) alert (' Error ')" >
4.3 Judging characters consist of letters and numbers, underscores, and dots. And the beginning can only be underlined and letters.
/^ ([A-za-z_]{1}) ([\w]*) $/g.test (str)
4.4 String substitution function. Replace ();
5. Browser class
5.1 Determining the type of browser
Window.navigator.appName
5.2 To determine IE version
Window.navigator.appVersion
5.3 Determine the resolution of the client
Window.screen.height; Window.screen.width;

6. Combined class
6.1 Email's judgment.
function Ismail (mail)
{
Return (new RegExp (-\w+) | (/^\w+) | ( \.\w+)) *\@[a-za-z0-9]+ (\.| -) [a-za-z0-9]+) *\. [a-za-z0-9]+$/). Test (mail);
}
6.2 Verification of mobile phone number
6.3 Authentication of the 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]&& (D.getmonth () +1) ==a[4]&&d.getdate () ==a[5];
}
Else
{
var D = new Date (a[3]+ "/" +a[4]+ "/" +a[5]);
var B = D.getfullyear () ==a[3]&& (D.getmonth () +1) ==a[4]&&d.getdate () ==a[5];
}
if (! B) {alert ("Enter the ID number" + a[0] + "in the wrong birth date!" "); return false;}
}
return true;
}

Drawing:
<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 the Registration form:
<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 increased ranks)
<HTML>
<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> </TD></TR>
</TABLE>
</BODY>
</HTML>

1. ID Card Strict Verification:

<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), 11)
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 border=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 by Windy_sk\\n\\nspecial T Hanks 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>



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.