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 !?
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 !?
您制作一个正则表达式验证器并为您想要的字母提供一个正则表达式。
比如字母只有:
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="RegularExpressionValidator" ControlToValidate="TextBox1" ValidationExpression="[aA-zZ]"></asp:RegularExpressionValidator>
您还有文本框的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