c# - 限制TextBox Visual Studio C#的内容

标签 c# visual-studio-2010 web-applications error-handling textbox

我试图限制用户输入,以便用户只能向名为OrderID的文本框输入数字,并且只能向名为CustomerName的文本框输入字母。

是否可以在Visual Studio Web应用程序表单中执行此操作?用C#编码。如果是这样,我该怎么办?

一旦实现了上述内容,如果用户尝试输入无效的数据类型,我也必须处理异常。

如何才能做到这一点?任何帮助深表感谢! :)

最佳答案

使用正则表达式
对于文本,请使用它-^[a-zA-Z]*$
使用CompareValidator,用于数字

<asp:TextBox ID="txt" runat="server />
<asp:CompareValidator ID="cv" runat="server" ControlToValidate="txt" Type="Integer"
   Operator="DataTypeCheck" ErrorMessage="Value must be an integer!" />

关于c# - 限制TextBox Visual Studio C#的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12988808/

相关文章:

database - 私有(private)云上的 Web 应用程序?

c# - 如果包含特定单词,则替换整行的正则表达式

c# - 回调接口(interface)合约

c# - 如何创建前台任务?

visual-studio-2010 - VS2008升级到VS2010 "cannot open file ' mfc90d.lib'"

c++ - 'data variable' 是什么意思?

c++ - VS2010 构建了一个 exe 但无法调试它提示找不到它

web-services - Alfresco 和 webapp tomcat 并行

c# - 在 C#/.NET 中合并两个图像

python - 外语 Chatterbot 网络应用程序