验证textbox中只能输入中文 在vs2003里的textbox中怎么验证只能输入中文,不能输入特殊符号 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 private bool IsCh(string str) { Regex re = new Regex("^[\u4e00-\u9fa5]+$"); return re.IsMatch(str); } function(){ var reg = /^[\u4E00-\u9FA5]+$/; if(!reg.test(this)){ return false; } return true; } 添加TextBox控件的TextChanged事件,代码如下void TextBox1_TextChanged(object sender, EventArgs e){ int nSel = TextBox1.SelectionStart; TextBox1.Text = System.Text.RegularExpressions.Regex.Replace(TextBox1.Text,@"[^\u4E00-\u9FA5]", string.Empty); TextBox1.SelectionStart = nSel;} <script>function onlyNumber(e) { var isIE = document.all?true:false; var key; if(isIE) { key = window.event.keyCode; } else { key=e.which; } if((key > 57 || key < 48)&& key != 8 && key != 12 && key!=127 ) return false; else { return true; } } </script>文本框里面这样写<asp:TextBox ID="txtCount" runat="server" onkeypress="return onlyNumber(event)">1</asp:TextBox>“这个是除了数字以外。其他东西都不能填进去的”。我想关键就是key的值了。自己试试改key的值吧。我没时间去试。你自己琢磨吧!!希望对你有帮助。 onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\u4E00-\u9FA5]/g,''))" 用正则表达式/[^\u4E00-\u9FA5]/gg代表的是全局的! 求高手告诉我运行原因 winfrom POST提交一个数据包时候出现411错误 有关List集合分页问题 求教Winform 解析一个Json 结果放到DataTable里 添加word.dll 求C#正则替换网页连接 如何在关机前调用自编写WINDOWS服务程序 在网页跳转前的script对话框无法显示问题~! 一个极简单的问题 《倡议书》 谁帮忙将delphi程序段翻译成C# C# 自动接通来电后播放声音
{
Regex re = new Regex("^[\u4e00-\u9fa5]+$");
return re.IsMatch(str);
}
{
var reg = /^[\u4E00-\u9FA5]+$/;
if(!reg.test(this)){
return false;
}
return true;
}
{
int nSel = TextBox1.SelectionStart;
TextBox1.Text = System.Text.RegularExpressions.Regex.Replace(TextBox1.Text,@"[^\u4E00-\u9FA5]", string.Empty);
TextBox1.SelectionStart = nSel;
}
function onlyNumber(e)
{
var isIE = document.all?true:false;
var key;
if(isIE)
{
key = window.event.keyCode;
}
else
{
key=e.which;
}
if((key > 57 || key < 48)&& key != 8 && key != 12 && key!=127 )
return false;
else
{
return true;
}
}
</script>文本框里面这样写
<asp:TextBox ID="txtCount" runat="server" onkeypress="return onlyNumber(event)">1</asp:TextBox>“这个是除了数字以外。其他东西都不能填进去的”。我想关键就是key的值了。自己试试改key的值吧。我没时间去试。你自己琢磨吧!!希望对你有帮助。
g代表的是全局的!