亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

常用正則表達(dá)式 新舊身份證合法性驗(yàn)證及相互轉(zhuǎn)

系統(tǒng) 6792 0

關(guān)鍵字:正則表達(dá)式 模式匹配 Javascript

摘要:收集一些常用的正則表達(dá)式。

正則表達(dá)式用于字符串處理,表單驗(yàn)證等場合,實(shí)用高效,但用到時(shí)總是不太把握,以致往往要上網(wǎng)查一番。我將一些常用的表達(dá)式收藏在這里,作備忘之用。本貼隨時(shí)會(huì)更新。

匹配中文字符的正則表達(dá)式: [\u4e00-\u9fa5]

匹配雙字節(jié)字符(包括漢字在內(nèi)):[^\x00-\xff]

應(yīng)用:計(jì)算字符串的長度(一個(gè)雙字節(jié)字符長度計(jì)2,ASCII字符計(jì)1)

String.prototype.len=function(){return this.replace([^\x00-\xff]/g,"aa").length;}

匹配空行的正則表達(dá)式:\n[\s| ]*\r

匹配HTML標(biāo)記的正則表達(dá)式:/<(.*)>.*<\/\1>|<(.*) \/>/

匹配首尾空格的正則表達(dá)式:(^\s*)|(\s*$)

String.prototype.trim = function()
{
return this.replace(/(^\s*)|(\s*$)/g, "");
}

利用正則表達(dá)式分解和轉(zhuǎn)換IP地址:

下面是利用正則表達(dá)式匹配IP地址,并將IP地址轉(zhuǎn)換成對(duì)應(yīng)數(shù)值的Javascript程序:

function IP2V(ip)
{
re=/(\d+)\.(\d+)\.(\d+)\.(\d+)/g //匹配IP地址的正則表達(dá)式
if(re.test(ip))
{
return RegExp.$1*Math.pow(255,3))+RegExp.$2*Math.pow(255,2))+RegExp.$3*255+RegExp.$4*1
}
else
{
throw new Error("Not a valid IP address!")
}
}

不過上面的程序如果不用正則表達(dá)式,而直接用split函數(shù)來分解可能更簡單,程序如下:

var ip="10.100.20.168"
ip=ip.split(".")
alert("IP值是:"+(ip[0]*255*255*255+ip[1]*255*255+ip[2]*255+ip[3]*1))

匹配Email地址的正則表達(dá)式:\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*

匹配網(wǎng)址URL的正則表達(dá)式:http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?

利用正則表達(dá)式去除字串中重復(fù)的字符的算法程序:[注:此程序不正確,原因見本貼回復(fù)]

var s="abacabefgeeii"
var s1=s.replace(/(.).*\1/g,"$1")
var re=new RegExp("["+s1+"]","g")
var s2=s.replace(re,"")
alert(s1+s2) //結(jié)果為:abcefgi

我原來在CSDN上發(fā)貼尋求一個(gè)表達(dá)式來實(shí)現(xiàn)去除重復(fù)字符的方法,最終沒有找到,這是我能想到的最簡單的實(shí)現(xiàn)方法。思路是使用后向引用取出包括重復(fù)的字符,再以重復(fù)的字符建立第二個(gè)表達(dá)式,取到不重復(fù)的字符,兩者串連。這個(gè)方法對(duì)于字符順序有要求的字符串可能不適用。

得用正則表達(dá)式從URL地址中提取文件名的javascript程序,如下結(jié)果為page1

s="http://www.9499.net/page1.htm"
s=s.replace(/(.*\/){0,}([^\.]+).*/ig,"$2")
alert(s)

利用正則表達(dá)式限制網(wǎng)頁表單里的文本框輸入內(nèi)容:

用正則表達(dá)式限制只能輸入中文:onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\u4E00-\u9FA5]/g,''))"

用正則表達(dá)式限制只能輸入全角字符:onkeyup="value=value.replace(/[^\uFF00-\uFFFF]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\uFF00-\uFFFF]/g,''))"

用正則表達(dá)式限制只能輸入數(shù)字:onkeyup="value=value.replace(/[^\d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"

用正則表達(dá)式限制只能輸入數(shù)字和英文:onkeyup="value=value.replace(/[\W]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"

正則表達(dá)式,相關(guān)鏈接
http://blog.csdn.net/laily/category/19548.aspx
http://blog.csdn.net/laily/archive/2004/06/30/30525.aspx 微軟的正則表達(dá)式教程(五):選擇/編組和后向引用

http://blog.csdn.net/laily/archive/2004/06/30/30522.aspx 微軟的正則表達(dá)式教程(四):限定符和定位符

http://blog.csdn.net/laily/archive/2004/06/30/30517.aspx 微軟的正則表達(dá)式教程(三):字符匹配

http://blog.csdn.net/laily/archive/2004/06/30/30514.aspx 微軟的正則表達(dá)式教程(二):正則表達(dá)式語法和優(yōu)先權(quán)順序

http://blog.csdn.net/laily/archive/2004/06/30/30511.aspx 微軟的正則表達(dá)式教程(一):正則表達(dá)式簡介

http://blog.csdn.net/laily/archive/2004/06/30/30360.aspx 小程序大作為:高級(jí)查找/替換、正則表達(dá)式練習(xí)器、Javascript腳本程序調(diào)試器

http://blog.csdn.net/laily/archive/2004/06/24/25872.aspx 經(jīng)典正則表達(dá)式

正則表達(dá)式,正規(guī)表達(dá)式,正則表達(dá)式匹配,正則表達(dá)式語法,模式匹配,正規(guī)表達(dá)式匹配 javascript正則表達(dá)式 ASP正則表達(dá)式 ASP.NET正則表達(dá)式 C#正則表達(dá)式 JSP正則表達(dá)式 PHP正則表達(dá)式 VB.NET正則表達(dá)式 VBSCript正則表達(dá)式編程 delphi正則表達(dá)式 jscript

正則表達(dá)式 regular expression
正則表達(dá)式 RegExp
模式 pattern
匹配 Match
.NET命名空間: System.Text.RegularExpression

補(bǔ)充:
^\d+$  //匹配非負(fù)整數(shù)(正整數(shù) + 0)
^[0-9]*[1-9][0-9]*$  //匹配正整數(shù)
^((-\d+)|(0+))$  //匹配非正整數(shù)(負(fù)整數(shù) + 0)
^-[0-9]*[1-9][0-9]*$  //匹配負(fù)整數(shù)
^-?\d+$    //匹配整數(shù)
^\d+(\.\d+)?$  //匹配非負(fù)浮點(diǎn)數(shù)(正浮點(diǎn)數(shù) + 0)
^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$  //匹配正浮點(diǎn)數(shù)
^((-\d+(\.\d+)?)|(0+(\.0+)?))$  //匹配非正浮點(diǎn)數(shù)(負(fù)浮點(diǎn)數(shù) + 0)
^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$  //匹配負(fù)浮點(diǎn)數(shù)
^(-?\d+)(\.\d+)?$  //匹配浮點(diǎn)數(shù)
^[A-Za-z]+$  //匹配由26個(gè)英文字母組成的字符串
^[A-Z]+$  //匹配由26個(gè)英文字母的大寫組成的字符串
^[a-z]+$  //匹配由26個(gè)英文字母的小寫組成的字符串
^[A-Za-z0-9]+$  //匹配由數(shù)字和26個(gè)英文字母組成的字符串
^\w+$  //匹配由數(shù)字、26個(gè)英文字母或者下劃線組成的字符串
^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$    //匹配email地址
^[a-zA-z]+://匹配(\w+(-\w+)*)(\.(\w+(-\w+)*))*(\?\S*)?$  //匹配url

利用正則表達(dá)式去除字串中重復(fù)的字符的算法程序:

var s="abacabefgeeii"
var s1=s.replace(/(.).*\1/g,"$1")
var re=new RegExp("["+s1+"]","g")
var s2=s.replace(re,"")
alert(s1+s2) //結(jié)果為:abcefgi
===============================
如果var s = "abacabefggeeii"
結(jié)果就不對(duì)了,結(jié)果為:abeicfgg
正則表達(dá)式的能力有限

1.確認(rèn)有效電子郵件格式
下面的代碼示例使用靜態(tài) Regex.IsMatch 方法驗(yàn)證一個(gè)字符串是否為有效電子郵件格式。如果字符串包含一個(gè)有效的電子郵件地址,則 IsValidEmail 方法返回 true,否則返回 false,但不采取其他任何操作。您可以使用 IsValidEmail,在應(yīng)用程序?qū)⒌刂反鎯?chǔ)在數(shù)據(jù)庫中或顯示在 ASP.NET 頁中之前,篩選出包含無效字符的電子郵件地址。

[Visual Basic]
Function IsValidEmail(strIn As String) As Boolean
' Return true if strIn is in valid e-mail format.
Return Regex.IsMatch(strIn, ("^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$")
End Function
[C#]
bool IsValidEmail(string strIn)
{
// Return true if strIn is in valid e-mail format.
return Regex.IsMatch(strIn, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");
}


2.清理輸入字符串
下面的代碼示例使用靜態(tài) Regex.Replace 方法從字符串中抽出無效字符。您可以使用這里定義的 CleanInput 方法,清除掉在接受用戶輸入的窗體的文本字段中輸入的可能有害的字符。CleanInput 在清除掉除 @、-(連字符)和 .(句點(diǎn))以外的所有非字母數(shù)字字符后返回一個(gè)字符串。

[Visual Basic]
Function CleanInput(strIn As String) As String
' Replace invalid characters with empty strings.
Return Regex.Replace(strIn, "[^\w\.@-]", "")
End Function
[C#]
String CleanInput(string strIn)
{
// Replace invalid characters with empty strings.
return Regex.Replace(strIn, @"[^\w\.@-]", "");
}


3.更改日期格式
以下代碼示例使用 Regex.Replace 方法來用 dd-mm-yy 的日期形式代替 mm/dd/yy 的日期形式。

[Visual Basic]
Function MDYToDMY(input As String) As String
Return Regex.Replace(input, _
"\b(?<month>\d{1,2})/(?<day>\d{1,2})/(?<year>\d{2,4})\b", _
"${day}-${month}-${year}")
End Function
[C#]
String MDYToDMY(String input)
{
return Regex.Replace(input,
"\\b(?<month>\\d{1,2})/(?<day>\\d{1,2})/(?<year>\\d{2,4})\\b",
"${day}-${month}-${year}");
}
Regex 替換模式
本示例說明如何在 Regex.Replace 的替換模式中使用命名的反向引用。其中,替換表達(dá)式 ${day} 插入由 (?<day>...) 組捕獲的子字符串。

有幾種靜態(tài)函數(shù)使您可以在使用正則表達(dá)式操作時(shí)無需創(chuàng)建顯式正則表達(dá)式對(duì)象,而 Regex.Replace 函數(shù)正是其中之一。如果您不想保留編譯的正則表達(dá)式,這將給您帶來方便


4.提取 URL 信息
以下代碼示例使用 Match.Result 來從 URL 提取協(xié)議和端口號(hào)。例如,“http://www.contoso.com:8080/letters/readme.html”將返回“http:8080”。

[Visual Basic]
Function Extension(url As String) As String
Dim r As New Regex("^(?<proto>\w+)://[^/]+?(?<port>:\d+)?/", _
RegexOptions.Compiled)
Return r.Match(url).Result("${proto}${port}")
End Function
[C#]
String Extension(String url)
{
Regex r = new Regex(@"^(?<proto>\w+)://[^/]+?(?<port>:\d+)?/",
RegexOptions.Compiled);
return r.Match(url).Result("${proto}${port}");
}

一、正則表達(dá)式基礎(chǔ)知識(shí)
  我們先從簡單的開始。假設(shè)你要搜索一個(gè)包含字符“cat”的字符串,搜索用的正則表達(dá)式就是“cat”。如果搜索對(duì)大小寫不敏感,單詞“catalog”、“Catherine”、“sophisticated”都可以匹配。也就是說:


1.1句點(diǎn)符號(hào)
  假設(shè)你在玩英文拼字游戲,想要找出三個(gè)字母的單詞,而且這些單詞必須以“t”字母開頭,以“n”字母結(jié)束。另外,假設(shè)有一本英文字典,你可以用正則表達(dá)式搜索它的全部內(nèi)容。要構(gòu)造出這個(gè)正則表達(dá)式,你可以使用一個(gè)通配符??句點(diǎn)符號(hào)“.”。這樣,完整的表達(dá)式就是“t.n”,它匹配“tan”、“ten”、“tin”和“ton”,還匹配“t#n”、“tpn”甚至“tn”,還有其他許多無意義的組合。這是因?yàn)榫潼c(diǎn)符號(hào)匹配所有字符,包括空格、Tab字符甚至換行符:

1.2方括號(hào)符號(hào)
  為了解決句點(diǎn)符號(hào)匹配范圍過于廣泛這一問題,你可以在方括號(hào)(“[]”)里面指定看來有意義的字符。此時(shí),只有方括號(hào)里面指定的字符才參與匹配。也就是說,正則表達(dá)式“t[aeio]n”只匹配“tan”、“Ten”、“tin”和“ton”。但“Toon”不匹配,因?yàn)樵诜嚼ㄌ?hào)之內(nèi)你只能匹配單個(gè)字符:

1.4表示匹配次數(shù)的符號(hào)
  表一顯示了表示匹配次數(shù)的符號(hào),這些符號(hào)用來確定緊靠該符號(hào)左邊的符號(hào)出現(xiàn)的次數(shù):

  假設(shè)我們要在文本文件中搜索美國的社會(huì)安全號(hào)碼。這個(gè)號(hào)碼的格式是999-99-9999。用來匹配它的正則表達(dá)式如圖一所示。在正則表達(dá)式中,連字符(“-”)有著特殊的意義,它表示一個(gè)范圍,比如從0到9。因此,匹配社會(huì)安全號(hào)碼中的連字符號(hào)時(shí),它的前面要加上一個(gè)轉(zhuǎn)義字符“\”。

  圖一:匹配所有123-12-1234形式的社會(huì)安全號(hào)碼
  假設(shè)進(jìn)行搜索的時(shí)候,你希望連字符號(hào)可以出現(xiàn),也可以不出現(xiàn)??即,999-99-9999和999999999都屬于正確的格式。這時(shí),你可以在連字符號(hào)后面加上“?”數(shù)量限定符號(hào),如圖二所示:

  圖二:匹配所有123-12-1234和123121234形式的社會(huì)安全號(hào)碼
  下面我們再來看另外一個(gè)例子。美國汽車牌照的一種格式是四個(gè)數(shù)字加上二個(gè)字母。它的正則表達(dá)式前面是數(shù)字部分“[0-9]{ 4}”,再加上字母部分“[A-Z]{ 2}”。圖三顯示了完整的正則表達(dá)式。

  圖三:匹配典型的美國汽車牌照號(hào)碼,如8836KV
  1.5“否”符號(hào)
  “^”符號(hào)稱為“否”符號(hào)。如果用在方括號(hào)內(nèi),“^”表示不想要匹配的字符。例如,圖四的正則表達(dá)式匹配所有單詞,但以“X”字母開頭的單詞除外。

  圖四:匹配所有單詞,但“X”開頭的除外
  1.6圓括號(hào)和空白符號(hào)
  假設(shè)要從格式為“June26,1951”的生日日期中提取出月份部分,用來匹配該日期的正則表達(dá)式可以如圖五所示:

  圖五:匹配所有MothDD,YYYY格式的日期
  新出現(xiàn)的“\s”符號(hào)是空白符號(hào),匹配所有的空白字符,包括Tab字符。如果字符串正確匹配,接下來如何提取出月份部分呢?只需在月份周圍加上一個(gè)圓括號(hào)創(chuàng)建一個(gè)組,然后用OROAPI(本文后面詳細(xì)討論)提取出它的值。修改后的正則表達(dá)式如圖六所示:

  圖六:匹配所有MonthDD,YYYY格式的日期,定義月份值為第一個(gè)組
1.7其它符號(hào)
  為簡便起見,你可以使用一些為常見正則表達(dá)式創(chuàng)建的快捷符號(hào)。如表二所示:
  表二:常用符號(hào)

  例如,在前面社會(huì)安全號(hào)碼的例子中,所有出現(xiàn)“[0-9]”的地方我們都可以使用“\d”。修改后的正則表達(dá)式如圖七所示:


/*------------------------
功能:替換任何空白字符
-------------------------*/
function TrimString (strVal)
{
strTmp = strVal + "";
if (strTmp.length == 0)
return (strTmp);
reVal = /^\s*/;
strTmp = strTmp.replace (reVal, '');
reVal = /\s*$/;
return (strTmp.replace (reVal, ''));
}

/*------------------------
功能:檢測是否是有效數(shù)字
-------------------------*/
function Check_Num( num )
{
num = ( TrimString( num ) );
if (num.length == 0)
return (false);
return ( Number( num ) );
}

/*------------------------
功能:檢測是否是有效日期
-------------------------*/
function Check_Date (strDate)
{
strDate = (TrimString (strDate));
if (strDate.length == 0)
return (false);
reVal = /^([1-2]\d{3})[\/|\-](0?[1-9]|10|11|12)[\/|\-]([1-2]?[0-9]|0[1-9]|30|31)$/;
return (reVal.test (strDate));
}

/*------------------------
功能:檢測是否是有效Email
-------------------------*/
function Check_Email (strEmail)
{
strEmail = (TrimString (strEmail));
if (strEmail.length == 0)
return (false);

reVal = /^[\-!#\$%&'\*\+\\\.\/0-9=\?A-Z\^_`a-z{|}~]+@[\-!#\$%&'\*\+\\\.\/0-9=\?A-Z\^_`a-z{|}~]+(\.[\-!#\$%&'\*\+\\\.\/0-9=\?A-Z\^_`a-z{|}~]+)+$/;
return (reVal.test (strEmail));
}

/*------------------------
功能:檢測是否是有效時(shí)間
-------------------------*/
function Check_Time (strTime)
{
strTime = (TrimString (strTime));
if (strTime.length == 0)
return (false);

reVal = /^(([0-9]|[01][0-9]|2[0-3])(:([0-9]|[0-5][0-9])){0,2}|(0?[0-9]|1[0-1])(:([0-9]|[0-5][0-9])){0,2}\s?[aApP][mM])?$/;
return (reVal.test (strTime));
}

/*------------------------
功能:檢測是否是有效日期特定格式
-------------------------*/
function Check_Date_1 (strDate)
{
strDate = (TrimString (strDate));
if (strDate.length == 0)
return (false);
reVal = /^([1-2]\d{3})[\/](0?[1-9]|10|11|12)[\/]([1-2]?[0-9]|0[1-9]|30|31)$/;
return (reVal.test (strDate));
}

/*------------------------
功能:檢測是否是有效日期特定格式
-------------------------*/
function Check_Date_2 (strDate)
{
strDate = (TrimString (strDate));
if (strDate.length == 0)
return (false);
reVal = /^([1-2]\d{3})[\-](0[1-9]|10|11|12)[\-]([1-2][0-9]|0[1-9]|30|31)$/;
return (reVal.test (strDate));
}

/*--------------------------------------
功能:換行定行
---------------------------------------*/
function enter( form, temp )
{
if ( window.event.keyCode == 13 )
{
eval( form + temp + ".focus()" );
eval( form + temp + ".select()" );
}
else
return (false);
}

/*--------------------------------------
功能:檢查字符串長度
---------------------------------------*/
function ByteString (strVal)
{
nLen = 0;

for (i = 0; i < strVal.length; i ++)
{
if (strVal.charCodeAt (i) > 255)
nLen += 2;
else
nLen ++;
};
return (nLen);
}

/*--------------------------------------
功能:按要求截取字符串長度
---------------------------------------*/
function SubString(strVal,nStrLen)
{
nLen = 0;
nTemp = 0;
for (i = 0; i < strVal.length; i ++)
{
if (strVal.charCodeAt (i) > 255)
nLen += 2;
else
nLen ++;
if(nLen <= nStrLen)
nTemp = i;
else
break;
};
return(strVal.substr(0,nTemp+1));
}

/*------------------------
功能:檢測密碼,密碼只能由英文字母、數(shù)字、減號(hào)、下劃線、$、#、*、(和)構(gòu)成,且首位必須是英文字母
-------------------------*/
function Check_Pass( strPass )
{
strPass = ( TrimString( strPass ) );
if (strPass.length == 0)
return (false);
reVal = /^[a-zA-Z]{1}[a-zA-Z0-9-_$#*()]{0,29}$/;
return ( reVal.test (strPass) );
}

這是所有的,不過是PHP的,你自己轉(zhuǎn)換一下吧~~

# re: 正則表達(dá)式 2005-02-28 00:59 yongsheng

^(((19)|(20))\d{2})(((((-|/)0?)|0)[1-9])|((-|/)?1[0-2]))((((((-|/)0?)|0)[1-9])|((-|/)?[1-2][0-9]))|((-|/)?3[0-1]))$


2004-1-1格式

# re: 正則表達(dá)式 2005-03-07 14:33 yongsheng

一、驗(yàn)證類
1、數(shù)字驗(yàn)證內(nèi)
1.1 整數(shù)
1.2 大于0的整數(shù) (用于傳來的ID的驗(yàn)證)
1.3 負(fù)整數(shù)的驗(yàn)證
1.4 整數(shù)不能大于iMax
1.5 整數(shù)不能小于iMin
2、時(shí)間類
2.1 短時(shí)間,形如 (13:04:06)
2.2 短日期,形如 (2003-12-05)
2.3 長時(shí)間,形如 (2003-12-05 13:04:06)
2.4 只有年和月。形如(2003-05,或者2003-5)
2.5 只有小時(shí)和分鐘,形如(12:03)
3、表單類
3.1 所有的表單的值都不能為空
3.2 多行文本框的值不能為空。
3.3 多行文本框的值不能超過sMaxStrleng
3.4 多行文本框的值不能少于sMixStrleng
3.5 判斷單選框是否選擇。
3.6 判斷復(fù)選框是否選擇.
3.7 復(fù)選框的全選,多選,全不選,反選
3.8 文件上傳 過程中判斷文件類型
4、字符類
4.1 判斷字符全部由a-Z或者是A-Z的字字母組成
4.2 判斷字符由字母和數(shù)字組成。
4.3 判斷字符由字母和數(shù)字,下劃線,點(diǎn)號(hào)組成.且開頭的只能是下劃線和字母
4.4 字符串替換函數(shù).Replace();
5、瀏覽器類
5.1 判斷瀏覽器的類型
5.2 判斷ie的版本
5.3 判斷客戶端的分辨率

6、結(jié)合類
6.1 email的判斷。
6.2 手機(jī)號(hào)碼的驗(yàn)證
6.3 身份證的驗(yàn)證


二、功能類

1、時(shí)間與相關(guān)控件類
1.1 日歷
1.2 時(shí)間控件
1.3 萬年歷
1.4 顯示動(dòng)態(tài)顯示時(shí)鐘效果(文本,如OA中時(shí)間)
1.5 顯示動(dòng)態(tài)顯示時(shí)鐘效果 (圖像,像手表)
2、表單類
2.1 自動(dòng)生成表單
2.2 動(dòng)態(tài)添加,修改,刪除下拉框中的元素
2.3 可以輸入內(nèi)容的下拉框
2.4 多行文本框中只能輸入iMax文字。如果多輸入了,自動(dòng)減少到iMax個(gè)文字(多用于短信發(fā)送)

3、打印類
3.1 打印控件
4、事件類
4.1 屏蔽右鍵
4.2 屏蔽所有功能鍵
4.3 --> 和<-- F5 F11,F9,F1
4.4 屏蔽組合鍵ctrl+N
5、網(wǎng)頁設(shè)計(jì)類
5.1 連續(xù)滾動(dòng)的文字,圖片(注意是連續(xù)的,兩段文字和圖片中沒有空白出現(xiàn))
5.2 html編輯控件類
5.3 顏色選取框控件
5.4 下拉菜單
5.5 兩層或多層次的下拉菜單
5.6 仿IE菜單的按鈕。(效果如rongshuxa.com的導(dǎo)航欄目)
5.7 狀態(tài)欄,title欄的動(dòng)態(tài)效果(例子很多,可以研究一下)
5.8 雙擊后,網(wǎng)頁自動(dòng)滾屏
6、樹型結(jié)構(gòu)。
6.1 asp+SQL版
6.2 asp+xml+sql版
6.3 java+sql或者java+sql+xml
7、無邊框效果的制作
8、連動(dòng)下拉框技術(shù)
9、文本排序


一、驗(yàn)證類
1、數(shù)字驗(yàn)證內(nèi)
1.1 整數(shù)
/^(-|\+)?\d+$/.test(str)
1.2 大于0的整數(shù) (用于傳來的ID的驗(yàn)證)
/^\d+$/.test(str)
1.3 負(fù)整數(shù)的驗(yàn)證
/^-\d+$/.test(str)
2、時(shí)間類
2.1 短時(shí)間,形如 (13:04:06)
function isTime(str)
{
var a = str.match(/^(\d{1,2})(:)?(\d{1,2})\2(\d{1,2})$/);
if (a == null) {alert('輸入的參數(shù)不是時(shí)間格式'); return false;}
if (a[1]>24 || a[3]>60 || a[4]>60)
{
alert("時(shí)間格式不對(duì)");
return false
}
return true;
}
2.2 短日期,形如 (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 長時(shí)間,形如 (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 只有年和月。形如(2003-05,或者2003-5)
2.5 只有小時(shí)和分鐘,形如(12:03)
3、表單類
3.1 所有的表單的值都不能為空
<input onblur="if(this.value.replace(/^\s+|\s+$/g,'')=='')alert('不能為空!')">
3.2 多行文本框的值不能為空。
3.3 多行文本框的值不能超過sMaxStrleng
3.4 多行文本框的值不能少于sMixStrleng
3.5 判斷單選框是否選擇。
3.6 判斷復(fù)選框是否選擇.
3.7 復(fù)選框的全選,多選,全不選,反選
3.8 文件上傳 過程中判斷文件類型
4、字符類
4.1 判斷字符全部由a-Z或者是A-Z的字字母組成
<input onblur="if(/[^a-zA-Z]/g.test(this.value))alert('有錯(cuò)')">
4.2 判斷字符由字母和數(shù)字組成。
<input onblur="if(/[^0-9a-zA-Z]/g.test(this.value))alert('有錯(cuò)')">
4.3 判斷字符由字母和數(shù)字,下劃線,點(diǎn)號(hào)組成.且開頭的只能是下劃線和字母
/^([a-zA-z_]{1})([\w]*)$/g.test(str)
4.4 字符串替換函數(shù).Replace();
5、瀏覽器類
5.1 判斷瀏覽器的類型
window.navigator.appName
5.2 判斷ie的版本
window.navigator.appVersion
5.3 判斷客戶端的分辨率
window.screen.height; window.screen.width;

6、結(jié)合類
6.1 email的判斷。
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 手機(jī)號(hào)碼的驗(yàn)證
6.3 身份證的驗(yàn)證
function isIdCardNo(num)
{
if (isNaN(num)) {alert("輸入的不是數(shù)字!"); 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("輸入的數(shù)字位數(shù)不對(duì)!"); return false;}
var a = num.match(re);
if (a != null)
{
if (len==15)
{
var D = new Date("19"+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("輸入的身份證號(hào) "+ a[0] +" 里出生日期不對(duì)!"); return false;}
}
return true;
}

3.7 復(fù)選框的全選,多選,全不選,反選
<form name=hrong>
<input type=checkbox name=All onclick="checkAll('mm')">全選<br/>
<input type=checkbox name=mm onclick="checkItem('All')"><br/>
<input type=checkbox name=mm onclick="checkItem('All')"><br/>
<input type=checkbox name=mm onclick="checkItem('All')"><br/>
<input type=checkbox name=mm onclick="checkItem('All')"><br/>
<input type=checkbox name=mm onclick="checkItem('All')"><br/><br/>


<input type=checkbox name=All2 onclick="checkAll('mm2')">全選<br/>
<input type=checkbox name=mm2 onclick="checkItem('All2')"><br/>
<input type=checkbox name=mm2 onclick="checkItem('All2')"><br/>
<input type=checkbox name=mm2 onclick="checkItem('All2')"><br/>
<input type=checkbox name=mm2 onclick="checkItem('All2')"><br/>
<input type=checkbox name=mm2 onclick="checkItem('All2')"><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 .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.checked){ all.checked = false; break;}
}
}
else all.checked = false;
}
</SCRIPT>

3.8 文件上傳 過程中判斷文件類型
<input type=file onchange="alert(this.value.match(/^(.*)(\.)(.{1,8})$/)[3])">

畫圖:
<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>

寫注冊表:
<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相關(guān)(客戶端動(dòng)態(tài)增加行列)
<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 onload="numberCells()">
<TABLE id=mytable border=1>
<TR><TH>&nbsp;</TH><TH>&nbsp;</TH><TH>&nbsp;</TH><TH>&nbsp;</TH></TR>
<TR><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD></TR>
<TR><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD></TR>
</TABLE>
</BODY>
</HTML>

1.身份證嚴(yán)格驗(yàn)證:

<script>
var aCity={11:"北京",12:"天津",13:"河北",14:"山西",15:"內(nèi)蒙古",21:"遼寧",22:"吉林",23:"黑龍江",31:"上海",32:"江蘇",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山東",41:"河南",42:"湖北",43:"湖南",44:"廣東",45:"廣西",46:"海南",50:"重慶",51:"四川",52:"貴州",53:"云南",54:"西藏",61:"陜西",62:"甘肅",63:"青海",64:"寧夏",65:"新疆",71:"臺(tái)灣",81:"香港",82:"澳門",91:"國外"}

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:非法地區(qū)";
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:非法生日";
for(var i = 17;i>=0;i --) iSum += (Math.pow(2,i) % 11) * parseInt(sId.charAt(17 - i),11)
if(iSum%11!=1)return "Error:非法證號(hào)";
return aCity[parseInt(sId.substr(0,2))]+","+sBirthday+","+(sId.substr(16,1)%2?"男":"女")
}

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

2.驗(yàn)證IP地址
<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.加sp1后還能用的無邊框窗口??!
<HTML XMLNS:IE>
<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 Thanks For andot ---*/

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

/*--- Thanks 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 onclick='parent.open(this.href);return false' $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';parent.if_max=!parent.if_max;parent.show_CW();\" onmouseup='parent.drag_up(event)' onmousemove='parent.drag_move(event)' onmousedown='parent.drag_down(event)' onselectstart='return false' oncontextmenu='return false'>";
temp += "<td style='color:#ffffff;padding-left:5px'>Chromeless Window For IE6 SP1</td>";
temp += "<td style='color:#ffffff;padding-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 Thanks For andot')\" style=\""+CSStext+"font-family:System;padding-right:2px;\">?</span>";
temp += "<span id=Min onclick='parent.New_CW.hide();parent.blur()' style=\""+CSStext+"font-family:Webdings;\" title='Minimum'>0</span>";
temp += "<span id=Max onclick=\"this.innerText=this.innerText=='1'?'2':'1';parent.if_max=!parent.if_max;parent.show_CW();\" style=\""+CSStext+"font-family:Webdings;\" title='Maximum'>1</span>";
temp += "<span id=Close onclick='parent.opener=null;parent.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>

電話號(hào)碼的驗(yàn)證

要求:
  (1)電話號(hào)碼由數(shù)字、"("、")"和"-"構(gòu)成
  (2)電話號(hào)碼為3到8位
  (3)如果電話號(hào)碼中包含有區(qū)號(hào),那么區(qū)號(hào)為三位或四位
  (4)區(qū)號(hào)用"("、")"或"-"和其他部分隔開
  (5)移動(dòng)電話號(hào)碼為11或12位,如果為12位,那么第一位為0
  (6)11位移動(dòng)電話號(hào)碼的第一位和第二位為"13"
  (7)12位移動(dòng)電話號(hào)碼的第二位和第三位為"13"
  根據(jù)這幾條規(guī)則,可以與出以下正則表達(dá)式:
  (^[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 onclick="PhoneCheck(document.all.iphone.value)" value="Check">

具有在輸入非數(shù)字字符不回顯的效果,即對(duì)非數(shù)字字符的輸入不作反應(yīng)。
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;
}
}

驗(yàn)證ip

str=document.RegExpDemo.txtIP.value;
if(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.test(str)==false)
{
window.alert('錯(cuò)誤的IP地址格式');
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('錯(cuò)誤的IP地址');
document.RegExpDemo.txtIP.select();
document.RegExpDemo.txtIP.focus();
return;
}
//剔除 如 010.020.020.03 前面 的0
var str=str.replace(/0(\d)/g,"$1");
str=str.replace(/0(\d)/g,"$1");
window.alert(str);


//一下是取數(shù)據(jù)的類
//Obj參數(shù)指定數(shù)據(jù)的來源(限定Table),默認(rèn)第一行為字段名稱行
//GetTableData類提供MoveNext方法,參數(shù)是表的行向上或向下移動(dòng)的位數(shù),正數(shù)向下移動(dòng),負(fù)數(shù)向上.
//GetFieldData方法獲得指定的列名的數(shù)據(jù)
//Sort_desc方法對(duì)指定的列按降序排列
//Sort_asc方法對(duì)指定的列按升序排列
//GetData方法返回字段值為特定值的數(shù)據(jù)數(shù)組,提供數(shù)據(jù),可以在外部進(jìn)行其他處理
//Delete方法刪除當(dāng)前記錄,數(shù)組減少一行
//初始化,Obj:table的名字,Leftlen:左面多余數(shù)據(jù)長度,Rightlen:右面多余數(shù)據(jù)長度,
function GetTableData(Obj,LeftLen,RightLen){
var MyObj=document.all(Obj);
var iRow=MyObj.rows.length;
var iLen=MyObj.rows[0].cells.length;
var i,j;

TableData=new Array();
for (i=0;i< iRow;i++){
TableData=new Array();
for (j=0;j<iLen;j++){
TableStr=MyObj.rows(i).cells(j).innerText;
TableStr=TableStr.substring(LeftLen, TableStr.length-RightLen).Trim();
TableStr=TableStr.replace(/ /gi,"").replace(/\r\n/ig,"");
TableData[j]=TableStr;
}
}

this.TableData=TableData;
this.cols=this.TableData[0].length;
this.rows=this.TableData.length;
this.rowindex=0;
}


function movenext(Step){
if (this.rowindex>=this.rows){
return
}

if (Step=="" || typeof(Step)=="undefined") {
if (this.rowindex<this.rows-1)
this.rowindex++;
return;

}
else{
if (this.rowindex + Step<=this.rows-1 && this.rowindex + Step>=0 ){
this.rowindex=this.rowindex + Step;
}
else
{
if (this.rowindex + Step<0){
this.rowindex= 0;
return;
}
if (this.rowindex + Step>this.rows-1){
this.rowindex= this.rows-1;
return;
}
}
}
}


function getfielddata(Field){
var colindex=-1;
var i=0;
if (typeof(Field) == "number"){
colindex=Field;
}
else
{
for (i=0;i<this.cols && this.rowindex<this.rows ;i++){
if (this.TableData[0]==Field){
colindex=i;
break;
}
}
}
if (colindex!=-1) {
return this.TableData[this.rowindex][colindex];
}

}



function sort_desc(){//降序
var colindex=-1;
var highindex=-1;
desc_array=new Array();
var i,j;
for (n=0; n<arguments.length; n++){
Field=arguments[arguments.length-1-n];
for (i=0;i<this.cols;i++){
if (this.TableData[0]==Field){
colindex=i;
break;
}
}
if ( colindex==-1 )
return;
else
{
desc_array[0]=this.TableData[0];
for(i=1;i<this.rows;i++){
desc_array=this.TableData[1];
highindex=1;
for(j=1;j<this.TableData.length;j++){
if (desc_array[colindex]<this.TableData[j][colindex]){
desc_array=this.TableData[j];
highindex=j;
}

}
if (highindex!=-1)
this.TableData=this.TableData.slice(0,highindex).concat(this.TableData.slice(highindex+1,this.TableData.length));
}
}


this.TableData=desc_array;
}
return;
}



function sort_asc(){//升序
var colindex=-1;
var highindex=-1;
var i,j;
for (n=0; n<arguments.length; n++){
asc_array=new Array();
Field=arguments[arguments.length-1-n];
for (i=0;i<this.cols;i++){
if (this.TableData[0]==Field){
colindex=i;
break;
}
}
if ( colindex==-1 )
return;
else
{
asc_array[0]=this.TableData[0];
for(i=1;i<this.rows;i++){
asc_array=this.TableData[1];
highindex=1;
for(j=1;j<this.TableData.length;j++){//找出最小的列值
if (asc_array[colindex]>this.TableData[j][colindex]){
asc_array=this.TableData[j];
highindex=j;

}

}
if (highindex!=-1)
this.TableData=this.TableData.slice(0,highindex).concat(this.TableData.slice(highindex+1,this.TableData.length));

}
}


this.TableData=asc_array;
}
return;
}



function getData(Field,FieldValue){
var colindex=-1;
var i,j;

GetData=new Array();
if (typeof(Field)=="undefined" || typeof(FieldValue)=="undefined" ){
return this.TableData;
}

for(j=0;j<this.cols;j++){
if (this.TableData[0][j]==Field){
colindex=j;
}
}
if (colindex!=-1){

for(i=1;i<this.rows;i++){
if (this.TableData[colindex]==FieldValue){
GetData=new Array();
GetData=this.TableData;
}
}
}
return GetData;
}
function DeletE(){
this.TableData=this.TableData.slice(0,this.rowindex).concat(this.TableData.slice(this.rowindex+1,this.TableData.length));
this.rows=this.TableData.length;
return;
}
function updateField(Field,FieldValue){
var colindex=-1;
var i=0;
if (typeof(Field) == "number"){
colindex=Field;
}
else
{
for (i=0;i<this.cols && this.rowindex<this.rows ;i++){
if (this.TableData[0]==Field){
colindex=i;
break;
}
}
}
if (colindex!=-1) {
this.TableData[this.rowindex][colindex]=FieldValue;
}


}
function movefirst(){
this.rowindex=0;
}
function movelast(){
this.rowindex=this.rows-1;
}
function String.prototype.Trim() {return this.replace(/(^\s*)|(\s*$)/g,"");}
GetTableData.prototype.MoveNext = movenext;
GetTableData.prototype.GetFieldData = getfielddata;
GetTableData.prototype.Sort_asc = sort_asc;
GetTableData.prototype.Sort_desc = sort_desc;
GetTableData.prototype.GetData = getData;
GetTableData.prototype.Delete = DeletE;
GetTableData.prototype.UpdateField = updateField;
GetTableData.prototype.MoveFirst = movefirst;

具體的例子: http://202.119.73.208/NetEAn/com/test/jsprint.htm

在每個(gè)文本框的onblur事件中調(diào)用校驗(yàn)代碼,并且每個(gè)文本框中onKeyDown事件中寫一個(gè)enter轉(zhuǎn)tab函數(shù)

//回車鍵換為tab
function enterToTab()
{
if(event.srcElement.type != 'button' && event.srcElement.type != 'textarea'
&& event.keyCode == 13)
{
event.keyCode = 9;
}
}

新舊身份證合法性驗(yàn)證及相互轉(zhuǎn)換算法
1、關(guān)于中國居民身份證的常識(shí):
  我國現(xiàn)行使用公民身份證號(hào)碼有兩種尊循兩個(gè)國家標(biāo)準(zhǔn),〖GB 11643-1989〗和〖GB 11643-1999〗。
  〖GB 11643-1989〗中規(guī)定的是15位身份證號(hào)碼:排列順序從左至右依次為:六位數(shù)字地址碼,六位數(shù)字出生日期碼,三位數(shù)字順序碼,其中出生日期碼不包含世紀(jì)數(shù)。

  〖GB 11643-1999〗中規(guī)定的是18位身份證號(hào)碼:公民身份號(hào)碼是特征組合碼,由十七位數(shù)字本體碼和一位數(shù)字校驗(yàn)碼組成。排列順序從左至右依次為:六位數(shù)字地址碼,八位數(shù)字出生日期碼,三位數(shù)字順序碼和一位數(shù)字校驗(yàn)碼。

  地址碼:表示編碼對(duì)象常住戶口所在縣(市、旗、區(qū))的行政區(qū)劃代碼。
  出生日期碼:表示編碼對(duì)象出生的年、月、日,其中年份用四位數(shù)字表示,年、月、日之間不用分隔符。
  順序碼:表示同一地址碼所標(biāo)識(shí)的區(qū)域范圍內(nèi),對(duì)同年、同月、同日出生的人員編定的順序號(hào)。順序碼的奇數(shù)分給男性,偶數(shù)分給女性。
  校驗(yàn)碼:是根據(jù)前面十七位數(shù)字碼,按照ISO 7064:1983.MOD 11-2校驗(yàn)碼計(jì)算出來的檢驗(yàn)碼。
關(guān)于身份證號(hào)碼最后一位的校驗(yàn)碼的算法如下:
 ∑(a[i]*W[i]) mod 11 ( i = 2, 3, ..., 18 )

  "*" :表示乘號(hào)
  i:表示身份證號(hào)碼每一位的序號(hào),從右至左,最左側(cè)為18,最右側(cè)為1。
  a[i]:表示身份證號(hào)碼第 i 位上的號(hào)碼
  W[i]:表示第 i 位上的權(quán)值 W[i] = 2^(i-1) mod 11
  設(shè):R = ∑(a[i]*W[i]) mod 11 ( i = 2, 3, ..., 18 )
  C = 身份證號(hào)碼的校驗(yàn)碼
  則R和C之間的對(duì)應(yīng)關(guān)系如下表:
   R:0 1 2 3 4 5 6 7 8 9 10
   C:1 0 X 9 8 7 6 5 4 3 2
  由此看出 X 就是 10,羅馬數(shù)字中的 10 就是X,所以在新標(biāo)準(zhǔn)的身份證號(hào)碼中可能含有非數(shù)字的字母X。
2、算法:

/***/ /**
*
*/

package cxx.sourceCode.base;

import java.text.DateFormat;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.Date;
import java.util.Random;

/***/ /**
*
@author 成曉旭
*
*/

public class Identity ... {
// 位權(quán)值數(shù)組
private static byte []Wi = new byte [ 17 ];
// 身份證前部分字符數(shù)
private static final byte fPart = 6 ;
// 身份證算法求模關(guān)鍵值
private static final byte fMod = 11 ;
// 舊身份證長度
private static final byte oldIDLen = 15 ;
// 新身份證長度
private static final byte newIDLen = 18 ;
// 新身份證年份標(biāo)志
private static final StringyearFlag = " 19 " ;
// 校驗(yàn)碼串
private static final StringCheckCode = " 10X98765432 " ;
// 最小的行政區(qū)劃碼
private static final int minCode = 150000 ;
// 最大的行政區(qū)劃碼
private static final int maxCode = 700000 ;
// 舊身份證號(hào)碼
// privateStringoldIDCard="";
// 新身份證號(hào)碼
// privateStringnewIDCard="";
// 地區(qū)及編碼


// privateStringArea[][2]=
private static void setWiBuffer() _886_1000_Close
分享到:
評(píng)論

常用正則表達(dá)式 新舊身份證合法性驗(yàn)證及相互轉(zhuǎn)換算法


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊,切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會(huì)非常 感謝您的哦?。?!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 国产精品蜜臀 | 亚洲乱码一区二区三区在线观看 | 宅男噜噜噜66一区二区 | 四虎影视在线麻豆国产 | 天天拍天天干 | 丁香婷婷影音先锋5566 | 久草免费在线视频观看 | 在线视频综合视频免费观看 | 久久香蕉国产线看观看亚洲片 | 亚洲欧美日产综合一区二区三区 | 日韩另类视频 | 免费看一级a一片毛片 | 日本一级特级毛片视频 | 国产精品久久久久久久成人午夜 | 国产精品1区2区3区 国产精品1区2区3区在线播放 | 免费爱爱网站 | 日本一级网站 | 久操免费在线观看 | 91视频这里只有精品 | 国产午夜亚洲精品第一区 | 国产一区二区三区亚洲综合 | 久久黄色免费视频 | 日本永久免费 | 伊人999| 国产精品19禁在线观看2021 | 国产区在线观看视频 | 99婷婷久久精品国产一区二区 | 天天干天天操天天干 | 欧美在线观看视频 | 性欧美成人免费观看视 | 亚洲图片 中文字幕 | 国产成人一区 | 全午夜免费一级毛片 | 91探花视频在线观看 | 黄色片网站观看 | 亚洲性夜夜综合久久麻豆 | 久99久爱精品免费观看视频 | 天天操天天干天天爽 | 真实的国产乱xxxx | 亚洲欧美一区二区三区在线 | 亚洲国产婷婷香蕉久久久久久 |