< script > function test() { if(document.a.b.value.length>50) { alert("不能超过50个字符!"); document.a.b.focus(); return false; } } </ script > < form name =a onsubmit ="return test()" > < textarea name ="b" cols ="40" wrap ="VIRTUAL" rows ="6" ></ textarea > < input type ="submit" name ="Submit" value ="check" > </ form > 只能是汉字 < input onkeyup ="value=value.replace(/[^\u4E00-\u9FA5]/g,'')" > 只能是英文字符 < script language =javascript> function onlyEng() { if(!(event.keyCode > =65&&event.keyCode<=90)) event.returnValue=false; } </ script > < input onkeydown ="onlyEng();" > 只能是数字 < script language =javascript> function onlyNum() { if(!((event.keyCode > =48&&event.keyCode<=57)||(event.keyCode>=96&&event.keyCode<=105))) //考虑小键盘上的数字键 event.returnValue=false; } </ script > < input onkeydown ="onlyNum();" > 只能是英文字符和数字 < input onkeyup ="value=value.replace(/[\W]/g,'') " onbeforepaste ="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))" > 验证为email格式 < SCRIPT LANGUAGE =Javascript RUNAT =Server> 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 > <input type=text onblur=isEmail(this.value)> 屏蔽关键字(sex , fuck) - 已修改 < script language ="JavaScript1.2" > function test() { if((a.b.value.indexOf ("sex") == 0)||(a.b.value.indexOf ("fuck") == 0)){ alert("五讲四美三热爱"); a.b.focus(); return false;} } </ script > < form name =a onsubmit ="return test()" > < input type =text name =b> <input type ="submit" name ="Submit" value ="check" > </ form > 屏蔽关键字(sex , fuck) - 已修改 转载于:https://www.cnblogs.com/Dove/archive/2005/03/17/120300.html