显示在文本框中输入的文本的例外情况 [英] Showing exceptions for the text entered in the textbox
本文介绍了显示在文本框中输入的文本的例外情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
早上好
在一个页面中我有一个名称和按钮的文本框。
例如,如果我在文本框中输入任何数字或特殊字符并按下按钮,页面应该重定向到另一个页面并在那里显示任何异常。
protected void btnsubmit_Click( object sender,EventArgs e)
{
if (txtname.Text = )
{
}
else
{
Response.Redirect( Exceptions2.aspx);
}
}
请帮帮我。
解决方案
试试这个:
受保护 void btnsubmit_Click( object sender,EventArgs e)
{
匹配匹配=正则表达式.Match(txtname.Text, @ (?i)^ [az] +);
if (match.Success)
{
}
else
{
Response.Redirect( Exceptions2.aspx< /跨度>);
}
}
我建议你查一下: C#正则表达式备忘单 [ ^ ]。
- 阿米特
good morning
in one page i have a textbox for name and a button.
for example if i enter any number or special character in the textbox and press the button,the page should be redirected to another page and show any exception there.
protected void btnsubmit_Click(object sender, EventArgs e)
{
if (txtname.Text = "")
{
}
else
{
Response.Redirect("Exceptions2.aspx");
}
}
please help me.
解决方案
Try this:
protected void btnsubmit_Click(object sender, EventArgs e) { Match match = Regex.Match(txtname.Text, @"(?i)^[a-z]+"); if (match.Success) { } else { Response.Redirect("Exceptions2.aspx"); } }
Also I would suggest you to check : C# Regular Expressions Cheat Sheet[^].
--Amit
这篇关于显示在文本框中输入的文本的例外情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文