if (/[^/x00-/xff]/g.test(s)) alert("含有汉字");
else alert("全是字符")
全是数字
<input οnkeyup="value=value.replace(/[^/d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^/d]/g,''))">
A-Z、a-z
<input οnkeyup="value=value.replace(/[^a-z|A-Z]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^a-z|A-Z]/g,''))">
屏蔽一些键
function document.onkeydown()
{
var k = window.event.keyCode;
if (k == 116) //屏蔽退格删除键
//屏蔽 F5 刷新键
{
window.event.keyCode = 0;
window.event.returnValue= false;
}
if (k==122) //屏蔽F11
{
window.event.keyCode = 0;
window.event.returnValue= false;
}
if (window.event.ctrlKey && k == 82) //Ctrl + R
window.event.returnValue= false;
if (window.event.ctrlKey && k == 78) //屏蔽 Ctrl+n
window.event.returnValue= false;
if (window.event.ctrlKey && k == 87) //屏蔽 Ctrl+w
window.event.returnValue= false;
if (event.shiftKey && k==121) //屏蔽 shift+F10
window.event.returnValue= false;
if (window.event.srcElement.tagName == "A" && window.event.shiftKey)
window.event.returnValue = false; //屏蔽 shift 加鼠标左键新开一网页
if (window.event.altKey && k == 115) //屏蔽Alt+F4
{
window.showModelessDialog("about:blank","","dialogWidth:1px;dialogheight:1px");
return false;
}
if (window.event.altKey||k == 91) //屏蔽 Alt+ 方向键 →
{
alert("禁止使用ALT组合键进行非法操作!");
window.event.returnValue=false;
}
}
时间检查
<script language="javascript">
function chkform()
{
var code=new RegExp(/^((((1[6-9]|[2-9]/d)/d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]/d|3[01]))|(((1[6-9]|[2-9]/d)/d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]/d|30))|(((1[6-9]|[2-9]/d)/d{2})-0?2-(0?[1-9]|1/d|2[0-8]))|(((1[6-9]|[2-9]/d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-)) (20|21|22|23|[0-1]?/d):[0-5]?/d:[0-5]?/d$/);
var yqdate="2008-01-01 12:12:59";
var d=code.test(yqdate)
alert(d);
}
</script>
//04/23/2008
^(((0?[13578]|1[02])//(0?[1-9]|[12]/d|3[01])//((1[6-9]|[2-9]/d)/d{2}))|((0?[13456789]|1[012])//(0?[1-9]|[12]/d|30)//((1[6-9]|[2-9]/d)/d{2}))|(0?2//(0?[1-9]|1/d|2[0-8])//((1[6-9]|[2-9]/d)/d{2}))|(0?2//29//((1[6-9]|[2-9]/d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$