-1

Possible Duplicate:
ASP.NET TextBox filter

If i have a textbox and i want to add a validation too it, how can i then add a validation, so i Only can write some letters, maybe T, K, or U or Empty !? so other letters like G,f,d,s Can't be used !?

4

2 回答 2

0

您制作一个正则表达式验证器并为您想要的字母提供一个正则表达式。

比如字母只有:

<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="RegularExpressionValidator" ControlToValidate="TextBox1" ValidationExpression="[aA-zZ]"></asp:RegularExpressionValidator>
于 2012-09-14T09:30:16.563 回答
0

您还有文本框的KeyUp - KeyDown- KeyPress事件,当您在文本框中键入内容时将调用该事件。您可以在您想要允许或限制的任何字符上编写代码

public void OnKeyPress(object sender, KeyEventArgs e)
{
MessageBox.Show(e.KeyCode.ToString(), "Your input");  //f(e.KeyChar == 4) you can loop like this


}

或者你也可以使用 JavaScript 或 JQuery

于 2012-09-14T10:20:50.367 回答