C#里面怎样限制textBox控件里键入或粘贴的最小字符数最大字符数有MaxLength,那最小字符数呢??
解决方案 »
- 实现插入不同类型的数有问
- C#中窗体间控件的调用问题。
- 如何设置visual studio 2010 rc的括号自动标记
- .NET,你们是怎么学的啊?
- 安装包制作-卸载问题
- (初学)怎么让asp.net也防止,sql注入攻击呢?
- 2个listview 将lv1中的内容移动到lv2中去,如果lv2中有要移动的项 则不添加items 如果没有 则在lv2中添加items
- 在vb.net中结束程序用end就行了,在c#中用什么那???????
- 招使用MSN交流的C#、asp.net、xml,Matlab等的朋友!
- ASP.net连接数据库出现问题!
- 如何判断网络连接状态和获取网络IP地址
- c# 文件拷贝速度?
private void textBox1_Validating(object sender, CancelEventArgs e)
{
if (textBox1.Text.Length < 2)
{
MessageBox.Show("error");
textBox1.Text = "";
textBox1.Focus();
}
}
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<script type="text/javascript">
function CheckMinLength(Myobj)
{
var MyobjValue=Myobj.value;
var length=MyobjValue.replace(/[^\x00-\xff]/g,'xx').length; //中文占两个字节的 所以 转换成xx两位的 再计算长度
if(length<2)
{
alert('最小字节数不能小于2个!'); //错误的提示方法你自己看着办不一定使用alert
Myobj.focus();
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:TextBox ID ="txtName" runat="server" onblur="CheckMinLeng(this)"></asp:TextBox>
</form>
</body>
</html>