JavaScript表單驗(yàn)證集錦
當(dāng)前位置:點(diǎn)晴教程→知識(shí)管理交流
→『 技術(shù)文檔交流 』
<script language=javascript> function onlyEng() { if(!(event.keyCode>=65&&event.keyCode<=90)) event.returnValue=false; } function onlyNum() { if(!((event.keyCode>=48&&event.keyCode<=57)||(event.keyCode>=96&&event.keyCode<=105))) //考慮小鍵盤(pán)上的數(shù)字鍵 event.returnValue=false; } function isEmail(strEmail) { if (strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) return true; else alert("oh"); } </script> <div align="center"> <center> <table border="1" width="90%" cellspacing="0" cellpadding="0" style="font-size:14px" bordercolor="#000000" bordercolorlight="#000000" bordercolordark="#FFFFFF"> <tr> <td width="100%">只能是漢字:<input onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')"></td> </tr> <tr> <td width="100%">只能是英語(yǔ)字符:<input onkeydown="onlyEng();"></td> </tr> <tr> <td width="100%">只能是數(shù)字:<input onkeydown="onlyNum();"></td> </tr> <tr> <td width="100%">只能是數(shù)字:<input onkeyup="value=value.replace(/[^0-9]/g,'')"></td> </tr> <tr> <td width="100%">只能是英文字母和數(shù)字:<input onkeyup="value=value.replace(/[\W]/g,'') " onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"></td> </tr> <tr> <td width="100%">驗(yàn)證email格式:<input type=text onblur=isEmail(this.value)></td> </tr> <tr> <td width="100%"><a name=2></a><B style='color:black;background-color:#99ff99'>不能輸入漢字</B><INPUT onpaste="return false;" style="IME-MODE: disabled; WIDTH: 400px" value="I only accept English input! Thanks for corporation!" name=textfield> </td> </tr> </table> </center> </div> 該文章在 2010/8/18 10:33:18 編輯過(guò) |
關(guān)鍵字查詢(xún)
相關(guān)文章
正在查詢(xún)... |