WEBFORM
只能是汉字:<input onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')">
只能是英文字母:<input onkeyup="value=value.replace(/[\W]/g,'') 
只能是数字:<input onkeyup="value=value.replace(/[\d]/g,'') 限制字数:
<asp:RegularExpressionValidator id="revTextBox1" runat="server" ForeColor="Red" Display="Dynamic" ControlToValidate="textBox1" ValidationExpression="(\w|\W){1,100}">格式错误-只能输入不超过100个字符</asp:RegularExpressionValidator>WINFORMIf e.KeyChar.IsLetter(e.KeyChar) = False Then MsgBox("不是字符!", , "错误提示")
‘只用于检查输入的是否字符
If e.KeyChar.IsDigit(e.KeyChar) = False Then MsgBox("不是数字!", , "错误提示")
‘只用于检查输入的是否数字