[英]Textbox input control (number of characters, type of characters)
我有一個asp:文本框從用戶那里取一個容器號並驗證它,我怎樣才能確保輸入的字符串正好是11個字符長
示例>“CRLU123456789”
我建議您使用RegularExpressionValidator
。 它們很容易標記:
<asp:RegularExpressionValidator
ControlToValidate="NameOfTextBox" <!-- the input text box name -->
ValidationExpression="[a-zA-Z]{4}[UJZ]\d{9}"
ErrorMessage="Please enter a valid container number."
Display="Dynamic" <!-- this means it's display: none when no error -->
EnabledClientScript="true" <!-- this will perform JavaScript validation -->
runat="server" />
現在,使用EnabledClientScript="true"
它將實際使用JavaScript驗證控件,如果它已啟用,但是因為您仍然不能依賴它,您也需要驗證服務器端。 那么,你要做的就是在按鈕點擊中,你想要進行驗證,第一個代碼塊應該是:
this.Validate(); // validates all Validators on the page
if (!this.IsValid) { return; }
當您回發時,將顯示錯誤消息。
對此ValidationExpression使用RegularExpressionValidator控件: [a-zA-Z]{4}[ujzUJZ][0-9]{9}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.