[code]
<html>
<head><title>用正则表达式控制输入格式</title></head>
<body>
<form>
<table border="1">
<tr>
<td>只能输入中文:</td>
<td>
<input type="text" name="mark" οnkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\u4E00-\u9FA5]/g,''))" />
</td>
</tr>
<tr>
<td>只能输入数字:</td>
<td>
<input type="text" name="number" οnkeyup="value=value.replace(/[^\d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))" />
</td>
</tr>
<tr>
<td>只能输入数字和英文:</td>
<td>
<input type="text" name="alpha" οnkeyup="value=value.replace(/[\W]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))" />
</td>
</tr>
<tr>
<td>只能输入数字和英文还有中文:</td>
<td>
<input type="text" name="chinese" οnkeyup="value=value.replace(/[^\u4E00-\u9FA5^a-z^A-Z^0-9]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\u4E00-\u9FA5^a-z^A-Z^0-9]/g,''))" />
</td>
</tr>
<tr><td colspan="2"><input type="submit"/></td></tr>
</table>
</form>
</body>
</html>[/code]
<html>
<head><title>用正则表达式控制输入格式</title></head>
<body>
<form>
<table border="1">
<tr>
<td>只能输入中文:</td>
<td>
<input type="text" name="mark" οnkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\u4E00-\u9FA5]/g,''))" />
</td>
</tr>
<tr>
<td>只能输入数字:</td>
<td>
<input type="text" name="number" οnkeyup="value=value.replace(/[^\d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))" />
</td>
</tr>
<tr>
<td>只能输入数字和英文:</td>
<td>
<input type="text" name="alpha" οnkeyup="value=value.replace(/[\W]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))" />
</td>
</tr>
<tr>
<td>只能输入数字和英文还有中文:</td>
<td>
<input type="text" name="chinese" οnkeyup="value=value.replace(/[^\u4E00-\u9FA5^a-z^A-Z^0-9]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\u4E00-\u9FA5^a-z^A-Z^0-9]/g,''))" />
</td>
</tr>
<tr><td colspan="2"><input type="submit"/></td></tr>
</table>
</form>
</body>
</html>[/code]