午夜国产狂喷潮在线观看|国产AⅤ精品一区二区久久|中文字幕AV中文字幕|国产看片高清在线

    用htc實(shí)現(xiàn)驗(yàn)證模塊
    來(lái)源:易賢網(wǎng) 閱讀:875 次 日期:2014-09-25 09:45:03
    溫馨提示:易賢網(wǎng)小編為您整理了“用htc實(shí)現(xiàn)驗(yàn)證模塊”,方便廣大網(wǎng)友查閱!

    代碼如下:

    /***************************************************************************************

    * validate1.0

    * 此代碼版權(quán)歸海洋工作室ocean所有,您可以非商業(yè)目的使用、復(fù)制、修改此代碼,但需要

    * 保留本工作室的版權(quán)信息。如果您使用、修改此代碼為商業(yè)目的,請(qǐng)聯(lián)系本工作室取得使用許可。

    *

    * 如果您對(duì)本程序有什么建議,請(qǐng)email to:ocean@forever.net.cn。

    *

    * 海洋工作室

    *

    * ocean() 制作

    *****************************************************************************************/

    //鍵盤事件

    <PUBLIC:ATTACH EVENT="onkeypress" ONEVENT="doEvent()" />

    //粘貼事件

    <PUBLIC:ATTACH EVENT="onpaste" ONEVENT="doEvent()" />

    //失去焦點(diǎn)事件

    <PUBLIC:ATTACH EVENT="onblur" ONEVENT="doEvent()" />

    <SCRIPT LANGUAGE="JScript">

    //預(yù)定義的檢查模式

    var regArray = new Array(

    new Array("int+0","^\\d+$","","需要輸入一個(gè)非負(fù)整數(shù),請(qǐng)重新檢查"), //非負(fù)整數(shù)(正整數(shù) + 0)

    new Array("int+","^[0-9]*[1-9][0-9]*$","^\\d+$","需要輸入一個(gè)正整數(shù),請(qǐng)重新檢查"), //正整數(shù)

    new Array("int-0","^((-\\d+)|(0+))$","^(-|(-\\d+)|(0+))$","需要輸入一個(gè)非正整數(shù),請(qǐng)重新檢查"), //非正整數(shù)(負(fù)整數(shù) + 0)

    new Array("int-","^-[0-9]*[1-9][0-9]*$","^(-|(-\\d+)|(0+))$","需要輸入一個(gè)負(fù)整數(shù),請(qǐng)重新檢查"), //負(fù)整數(shù)

    new Array("int","^-?\\d+$","^-|(-?\\d+)$","需要輸入一個(gè)整數(shù),請(qǐng)重新檢查"), //整數(shù)

    new Array("double+0","^\\d+(","需要輸入一個(gè)非負(fù)浮點(diǎn)數(shù),請(qǐng)重新檢查"), //非負(fù)浮點(diǎn)數(shù)(正浮點(diǎn)數(shù) + 0)

    new Array("double+","^(([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*))$","^((","需要輸入一個(gè)正浮點(diǎn)數(shù),請(qǐng)重新檢查"), //正浮點(diǎn)數(shù)

    new Array("double-0","^((-\\d+(","需要輸入一個(gè)非正浮點(diǎn)數(shù),請(qǐng)重新檢查"), //非正浮點(diǎn)數(shù)(負(fù)浮點(diǎn)數(shù) + 0)

    new Array("double-","^(-(([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*)))$","^(-|(-\\d+\\.?)|(-\\d+\\.\\d+))$","需要輸入一個(gè)負(fù)浮點(diǎn)數(shù),請(qǐng)重新檢查"), //負(fù)浮點(diǎn)數(shù)

    new Array("double","^(-?\\d+)(","需要輸入一個(gè)浮點(diǎn)數(shù),請(qǐng)重新檢查"), //浮點(diǎn)數(shù)

    new Array("char","^[A-Za-z]+$","","您只能輸入英文字母,請(qǐng)重新檢查"), //由26個(gè)英文字母組成的字符串

    new Array("upperchar","^[A-Z]+$","","您只能輸入英文大寫字母,請(qǐng)重新檢查"), //由26個(gè)英文字母的大寫組成的字符串

    new Array("lowerchar","^[a-z]+$","","您只能輸入英文小寫字母,請(qǐng)重新檢查"), //由26個(gè)英文字母的小寫組成的字符串

    new Array("digitchar","^[A-Za-z0-9]+$","","您只能輸入數(shù)字和英文字母,請(qǐng)重新檢查"), //由數(shù)字和26個(gè)英文字母組成的字符串

    new Array("digitchar_","^\\w+$","","您只能輸入數(shù)字、英文字母和下劃線,請(qǐng)重新檢查"), //由數(shù)字、26個(gè)英文字母或者下劃線組成的字符串

    new Array("email","^[\\w-]+(","需要輸入正確的email地址,請(qǐng)重新檢查"), //email地址

    new Array("url","^[a-zA-z]+://(>","需要輸入正確的url地址,請(qǐng)重新檢查") //url

    );

    //受控元素默認(rèn)的事件處理程序

    function doEvent() {

    //得到觸發(fā)事件的類型

    var type = window.event.type;

    //得到觸發(fā)元素的值。

    var value = window.event.srcElement.value;

    if (type == "keypress") { //如果是鍵盤按下事件,得到鍵盤按下后的值

    var keyCode = window.event.keyCode;

    if (typeof(window.event.srcElement.upper) != "undefined") { //如果定義了轉(zhuǎn)換大寫

    if (keyCode >= 97 && keyCode <= 122)

    keyCode = window.event.keyCode = keyCode - 32;

    }

    else if (typeof(window.event.srcElement.lower) != "undefined") { //如果定義了轉(zhuǎn)換小寫

    if (keyCode >= 65 && keyCode <= 90)

    keyCode = window.event.keyCode = keyCode + 32;

    }

    value += String.fromCharCode(keyCode);

    }

    else if (type == "paste") {

    value += window.clipboardData.getData("Text");

    }

    //如果觸發(fā)元素的值為空,則表示用戶沒(méi)有輸入,不接受檢查。

    if (value == "") return;

    //如果觸發(fā)元素沒(méi)有設(shè)置reg屬性,則返回不進(jìn)行任何檢查。

    if (typeof(window.event.srcElement.reg) == "undefined") return;

    //如果觸發(fā)元素沒(méi)有定義check屬性,則在按鍵和粘貼事件中不做檢查

    if ((type == "keypress" || type == "paste") && typeof(window.event.srcElement.check) == "undefined") return;

    //如果沒(méi)有通過(guò)檢查模式,出現(xiàn)的錯(cuò)誤信息

    var msg = "";

    //得到檢查模式

    var reg = window.event.srcElement.reg;

    //正則表達(dá)式對(duì)象

    var regExp = null;

    //從預(yù)定義的檢查模式中查找正則表達(dá)式對(duì)象

    for (var i=0;i<regArray.length;i++) {

    if (regArray[i][0] == reg) {

    if ((type == "keypress" || type == "paste") && regArray[i][2] != "")

    regExp = new RegExp(regArray[i][2]); //查找到預(yù)定義的檢查模式

    else

    regExp = new RegExp(regArray[i][1]); //查找到預(yù)定義的檢查模式

    msg = regArray[i][3]; //定義預(yù)定義的報(bào)錯(cuò)信息

    break; //查找成功,退出循環(huán)

    }

    }

    if (regExp == null) { //如果沒(méi)有查找到預(yù)定義的檢查模式,說(shuō)明reg本身就為正則表達(dá)式對(duì)象。

    if ((type == "keypress" || type == "paste") && typeof(window.event.srcElement.regcheck) != "undefined")

    regExp = new RegExp(window.event.srcElement.regcheck); //按照用戶自定義的正則表達(dá)式生成正則表達(dá)式對(duì)象。

    else

    regExp = new RegExp(reg); //按照用戶自定義的正則表達(dá)式生成正則表達(dá)式對(duì)象。

    msg = "輸入錯(cuò)誤,請(qǐng)重新檢查"; //錯(cuò)誤信息

    }

    //檢查觸發(fā)元素的值符合檢查模式,直接返回。

    if (regExp.test(value)) return;

    if (type == "blur") { //如果是失去焦點(diǎn)并且檢查不通過(guò),則需要出現(xiàn)錯(cuò)誤警告框。

    //判斷用戶是否自己定義了錯(cuò)誤信息

    if (typeof(window.event.srcElement.msg) != "undefined")

    msg = window.event.srcElement.msg;

    //顯示錯(cuò)誤信息

    alert(msg);

    //將焦點(diǎn)重新聚回觸發(fā)元素

    window.event.srcElement.focus();

    window.event.srcElement.select();

    }

    else { //如果是鍵盤按下或者粘貼事件并且檢查不通過(guò),則取消默認(rèn)動(dòng)作。

    //取消此次鍵盤按下或者粘貼操作

    window.event.returnValue = false;

    }

    }

    </SCRIPT>

    應(yīng)用例子:

    代碼如下:

    <html>

    <head>

    <style type="text/css">

    TABLE {

    width:100%;

    }

    INPUT {

    behavior:url("validate.htc");

    }

    </style>

    </head>

    <body style="margin:0">

    <table>

    <tr><td><a href="> border="0" src="logo.jpg"></a></td></tr>

    </table>

    <br>

    <table style="margin-left:20px">

    <tr>

    <td>驗(yàn)證規(guī)則</td>

    <td>實(shí)時(shí)檢測(cè)</td>

    <td>失去焦點(diǎn)時(shí)檢測(cè)</td>

    </tr>

    <tr>

    <td>非負(fù)整數(shù)(正整數(shù) + 0)</td>

    <td><input type="text" value="" reg="int+0" check></td>

    <td><input type="text" value="" reg="int+0"></td>

    </tr>

    <tr>

    <td>正整數(shù)</td>

    <td><input type="text" value="" reg="int+" check></td>

    <td><input type="text" value="" reg="int+"></td>

    </tr>

    <tr>

    <td>非正整數(shù)(負(fù)整數(shù) + 0)</td>

    <td><input type="text" value="" reg="int-0" check></td>

    <td><input type="text" value="" reg="int-0"></td>

    </tr>

    <tr>

    <td>負(fù)整數(shù)</td>

    <td><input type="text" value="" reg="int-" check></td>

    <td><input type="text" value="" reg="int-"></td>

    </tr>

    <tr>

    <td>整數(shù)</td>

    <td><input type="text" value="" reg="int" check></td>

    <td><input type="text" value="" reg="int"></td>

    </tr>

    <tr>

    <td>非負(fù)浮點(diǎn)數(shù)(正浮點(diǎn)數(shù) + 0)</td>

    <td><input type="text" value="" reg="double+0" check></td>

    <td><input type="text" value="" reg="double+0"></td>

    </tr>

    <tr>

    <td>正浮點(diǎn)數(shù)</td>

    <td><input type="text" value="" reg="double+" check></td>

    <td><input type="text" value="" reg="double+"></td>

    </tr>

    <tr>

    <td>非正浮點(diǎn)數(shù)(負(fù)浮點(diǎn)數(shù) + 0)</td>

    <td><input type="text" value="" reg="double-0" check></td>

    <td><input type="text" value="" reg="double-0"></td>

    </tr>

    <tr>

    <td>負(fù)浮點(diǎn)數(shù)</td>

    <td><input type="text" value="" reg="double-" check></td>

    <td><input type="text" value="" reg="double-"></td>

    </tr>

    <tr>

    <td>浮點(diǎn)數(shù)</td>

    <td><input type="text" value="" reg="double" check></td>

    <td><input type="text" value="" reg="double"></td>

    </tr>

    <tr>

    <td>由26個(gè)英文字母組成的字符串</td>

    <td><input type="text" value="" reg="char" check></td>

    <td><input type="text" value="" reg="char"></td>

    </tr>

    <tr>

    <td>由26個(gè)英文字母的大寫組成的字符串(輸入小寫字母會(huì)自動(dòng)轉(zhuǎn)換成大寫)</td>

    <td><input type="text" value="" reg="upperchar" check upper></td>

    <td><input type="text" value="" reg="upperchar" upper></td>

    </tr>

    <tr>

    <td>由26個(gè)英文字母的小寫組成的字符串(輸入大寫字母會(huì)自動(dòng)轉(zhuǎn)換成小寫)</td>

    <td><input type="text" value="" reg="lowerchar" check lower></td>

    <td><input type="text" value="" reg="lowerchar" lower></td>

    </tr>

    <tr>

    <td>由數(shù)字和26個(gè)英文字母組成的字符串</td>

    <td><input type="text" value="" reg="digitchar" check></td>

    <td><input type="text" value="" reg="digitchar"></td>

    </tr>

    <tr>

    <td>由數(shù)字、26個(gè)英文字母或者下劃線組成的字符串</td>

    <td><input type="text" value="" reg="digitchar_" check></td>

    <td><input type="text" value="" reg="digitchar_"></td>

    </tr>

    <tr>

    <td>email地址</td>

    <td><input type="text" value="" reg="email" check></td>

    <td><input type="text" value="" reg="email"></td>

    </tr>

    <tr>

    <td>url</td>

    <td><input type="text" value="" reg="url" check></td>

    <td><input type="text" value="" reg="url"></td>

    </tr>

    <tr>

    <td>自定義規(guī)則(只能輸入"aaa"),自定義報(bào)錯(cuò)信息</td>

    <td><input type="text" value="" reg="^aaa$" regcheck="^a{1,3}$" msg="只能輸入aaa" check></td>

    <td><input type="text" value="" reg="^aaa$" regcheck="^a{1,3}$" msg="只能輸入aaa"></td>

    </tr>

    </table>

    <hr width="50%" style="color: #FF0000">

    <div style="text-align:center;font-size:9pt">copyright 2004 © 海洋工作室(<a href=">)</div>

    <p> </p>

    <p> </p>

    <p> </p>

    <p> </p>

    </body>

    </html>

    更多信息請(qǐng)查看IT技術(shù)專欄

    更多信息請(qǐng)查看腳本欄目
    易賢網(wǎng)手機(jī)網(wǎng)站地址:用htc實(shí)現(xiàn)驗(yàn)證模塊
    由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

    2025國(guó)考·省考課程試聽(tīng)報(bào)名

    • 報(bào)班類型
    • 姓名
    • 手機(jī)號(hào)
    • 驗(yàn)證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 新媒體/短視頻平臺(tái) | 手機(jī)站點(diǎn) | 投訴建議
    工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
    云南網(wǎng)警備案專用圖標(biāo)
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
    云南網(wǎng)警報(bào)警專用圖標(biāo)