智慧大石
若是 asp.net B/S 的话,可直接用 ajax 的 FilteredTextBoxExtender 控件,用户在第一时间,键盘即不能 key-in 规定以外的字符:http://www.asp.net/ajax/ajaxcontroltoolkit/Samples/FilteredTextBox/FilteredTextBox.aspx只能輸入大小寫的英文字母<ajaxToolkit:FilteredTextBoxExtender ID="FilteredTextBoxExtender1" runat="server" TargetControlID="TextBox1" FilterType="UppercaseLetters, LowercaseLetters, Custom" ValidChars=" " />只能輸入大小寫的英文字母、半形空格<ajaxToolkit:FilteredTextBoxExtender ID="FilteredTextBoxExtender1" runat="server" TargetControlID="TextBox1" FilterType="UppercaseLetters, LowercaseLetters" />只能輸入大小寫的英文字母、數字 (不包括小數點)<ajaxToolkit:FilteredTextBoxExtender ID="FilteredTextBoxExtender1" runat="server" TargetControlID="TextBox1" FilterType="UppercaseLetters, LowercaseLetters, Numbers" />只能輸入數字 (不包括小數點)<ajaxToolkit:FilteredTextBoxExtender ID="FilteredTextBoxExtender1" runat="server" TargetControlID="TextBox1" FilterType="Numbers" />只能輸入數字 1~8 (不包括小數點)<ajaxToolkit:FilteredTextBoxExtender ID="FilteredTextBoxExtender1" runat="server" TargetControlID="TextBox1" FilterType="Custom" ValidChars="12345678" />只能輸入數字 (包括小數點)<ajaxToolkit:FilteredTextBoxExtender ID="FilteredTextBoxExtender1" runat="server" TargetControlID="TextBox1" FilterType="Numbers, Custom" ValidChars="." />電話號碼<ajaxToolkit:FilteredTextBoxExtender ID="FilteredTextBoxExtender1" runat="server" TargetControlID="TextBox1" FilterType="Numbers, Custom" ValidChars="(-)#" />出生年月日 (全形)<ajaxToolkit:FilteredTextBoxExtender ID="FilteredTextBoxExtender1" runat="server" TargetControlID="TextBox1" FilterType="Custom" ValidChars="一二三四五六七八九零十年月日" />