<head>
<script type="text/javascript">
function maskEdit(pattern) {
var src = event.srcElement;
var selRange = document.selection.createRange();
var srcRange = src.createTextRange();
selRange.setEndPoint("StartToStart", srcRange);
var num = selRange.text + String.fromCharCode(event.keyCode) + srcRange.text.substr(selRange.text.length);
event.returnValue = pattern.test(num);
}
</script>
</head>
<body>
<input type="text" onkeypress="maskEdit(/^[\w]*$/)" />
</body>
</html>
___________________________________________________________
1 function pCheck() 2 { 3 if (form.username.value != "") 4 { 5 if (!strangecode(form.username.value)) 6 { 7 form.username.focus(); 8 return false; 9 } 10 } 11 } 12 //验证特殊字符 13 function strangecode(code) 14 { var strangCode = "~`#%^&\'\"<>"; 15 var temp; 16 for (var i = 0; i