文本框验证中的问题 [英] Problem in Validation of a Text Box
本文介绍了文本框验证中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我在应用程序中使用文本框输入年龄,对于我的应用程序,年龄应在10到120之间.我尝试了以下代码,但它不起作用.
Hello All,
I am using a Text Box in my application for entering age, and the for my application the age should be between 10 and 120. I tried the following code, but it is not working.
protected void CustomValidator2_ServerValidate(object source, ServerValidateEventArgs args)
{
/*DateTime dtStart = DateTime.Parse(Age.Text);
TimeSpan sp = DateTime.Now - dtStart;
if (sp.Days < 10 * 365)
{
args.IsValid = false;
CustomValidator2.ErrorMessage = "You are too small baby !!";
}
else if (sp.Days > 120 * 365)
{
args.IsValid = false;
CustomValidator2.ErrorMessage = "Sorry Grandpa!!";
}*/
int age_temp;
age_temp = Int32.Parse(Age.Text);
if((age_temp<10) && (age_temp>120)
args.IsValid=false;
else
args.IsValid=true;
}
尝试了两种方法,但徒劳无功.
也在网上搜索.
我知道这很简单,但是请帮忙.
问候
MK
Tried both the methods, but in vain.
Also searched in net.
I know this is very simple, but kindly assist.
Regards
MK
推荐答案
if((age_temp<10) && (age_temp>120)
我认为您的意思是"||"不是&&"不是吗?
或"应该比和"更好.
I think you meant "||" not "&&" didn''t you?
"Or" should work better then "And"...
这篇关于文本框验证中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文