textBox 为空的或者字数大于30个字 提示内容为空和字数大于30个字 textBox 为空的或者字数大于30个字 提示内容为空和字数大于30个字 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 if(string.IsNullOrEmpty(textBox.Text)){ //内容为空}else if(textBox.Text.Length>30){//字数大于30个字} if(textBox.Text.Length==0)//提示内容为空if(textBox.Text.Length>30)//提示字数大于30个字 if(textbox.text=="标题名"){response.write("alert('标题名不能重复')");} 用JQuery来实现:<script type="text/javascript"> $(document).ready(function () { $("#error").hide(); $("#Button1").click(function () { var $val = $("#Text1").val(); var code; if(code.length > 30 || code.length==0){ $("#error").show(); break; } for (var i = 0; i < $val.length; i++) { //charAt()获取指定位置字符串,charCodeAt()返回该字符串的编码 //0的ASCII是48,9的ASCII是57 var code = $val.charAt(i).charCodeAt(0); if (code < 48 || code > 57) { $("#error").show(); break; } else { $("#error").hide(); } } }); }); </script> 意思差不我就是这个样子了!如果你不用这个button 去实现,你可以让鼠标 onmousemoveout 事件来实现验证! 最好先Trim一下,不然按几下空格键,也算内容不为空,容易出错。.net 4.0里提供了String.IsNullOrWhitespace方法,就省去Trim的一步了 if(string.IsNullOrEmpty(textBox1.Text)){}else if(textBox1.Text.Length>30){} public string CheckData(string textBoxData){if(string.IsNullOrEmpty(textBoxData)||textBoxData.Length>30){ StringBuilder errorMSG=new StringBuilder(); if(string.IsNullOrEmpty(textBoxData)){ //内容为空 errorMSG.append("内容为空"); } if(textBoxData.Length>30){ //提示字数大于30个字 errorMSG.append("提示字数大于30个字"); }}return errorMSG.ToString();} c# word操作,表格总是被嵌套 发贴引用功能的正则表达式 web中,这个问题怎么解决 WinFrom 返回上一个panel mysql 部分中文无法insert问题——已发100分贴等待帮助 .net framework区分32位还是64位吗? C#有个很简单的程序不知道写 在DATAGRID导到EXCEL中的时候,数据格式如何保持不变,各位大哥帮忙解答一下,谢谢! c# 水晶报表程序的图表显示问题 如何将byte [] 数组写入Stream中 大侠们看看这个Datagridview是怎么了 在.Net平台上实现多个Web服务集成
{
//内容为空
}
else if(textBox.Text.Length>30)
{
//字数大于30个字
}
//提示内容为空
if(textBox.Text.Length>30)
//提示字数大于30个字
{
response.write("alert('标题名不能重复')");
}
$(document).ready(function () {
$("#error").hide();
$("#Button1").click(function () {
var $val = $("#Text1").val();
var code; if(code.length > 30 || code.length==0){
$("#error").show();
break;
}
for (var i = 0; i < $val.length; i++) {
//charAt()获取指定位置字符串,charCodeAt()返回该字符串的编码
//0的ASCII是48,9的ASCII是57
var code = $val.charAt(i).charCodeAt(0);
if (code < 48 || code > 57) {
$("#error").show();
break;
}
else {
$("#error").hide();
}
}
});
});
</script>
意思差不我就是这个样子了!
如果你不用这个button 去实现,你可以让鼠标 onmousemoveout 事件来实现验证!
.net 4.0里提供了String.IsNullOrWhitespace方法,就省去Trim的一步了
{
}
else if(textBox1.Text.Length>30)
{
}
if(string.IsNullOrEmpty(textBoxData)||textBoxData.Length>30)
{
StringBuilder errorMSG=new StringBuilder();
if(string.IsNullOrEmpty(textBoxData)){
//内容为空
errorMSG.append("内容为空");
}
if(textBoxData.Length>30){
//提示字数大于30个字
errorMSG.append("提示字数大于30个字");
}
}
return errorMSG.ToString();
}