我的无效字符代码无法验证 [英] My Invalid Character Code does not validate
本文介绍了我的无效字符代码无法验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
美好的一天,
我正在创建一个网络表单,我正在尝试验证一些文本框,例如我不希望最终用户在ID文本框中插入字母..
以下是我的代码,请告诉我是否使用旧方法< br $> b $ b
Good Day,
I am creating a web form and I am trying to validate some textboxes e.g. I don't want the end user to insert letters in ID text box..
Here are my codes below and please advise me if I am using an old method
protected void txtID_TextChanged(object sender, EventArgs e)
{
foreach (char cr in txtID.Text)
{
if (char.IsDigit(cr) == false)
{
Console.Write("Invalid Charactor"","Error Message")
}
}
我双击了文本框并开始编码.....
I have double click the text box and started my coding.....
推荐答案
您好,
您可以使用自定义验证器控件。
看看这个: CustomValidator,contrôle - MSDN - Microsoft
试试这个
Try this
<asp:CompareValidator runat="server" Operator="DataTypeCheck" Type="Integer"
ControlToValidate="ValueTextBox" ErrorMessage="Value must be a whole number" />
希望这会有所帮助
Hope this helps
这篇关于我的无效字符代码无法验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文