The RegularExpressionValidator control is used to verify whether the input value matches the pattern specified by the regular expression.
Attribute:
ControlToValidate = "Name of the control to be verified"
ValidationExpression = "verification rules"
ErrorMessage = "error message to be displayed"
Text = "message displayed when verification fails ."
ForeColor = "color of the prompt message"
Page Structure:
HTML code:
<% -- Add button -- %>
<Asp: Button ID = "btnAdd" runat = "server" Text = "" onclick = "btnAdd_Click" ValidationGroup = "checkText"/>
<% -- The project name must be a Chinese character, and the maximum number of people must be a number -- %>
<Asp: regularExpressionValidator ID = "regular" runat = "server" ValidationGroup = "checkText" ControlToValidate = "txtEventName" ErrorMessage = "* The project name can only contain Chinese characters" ValidationExpression = "^ [\ 1- \ tags] {0 ,} $ "/>
<% -- The maximum number of verified reports must be a number -- %>
<Asp: regularExpressionValidator ID = "regular" runat = "server" ValidationGroup = "checkText" ControlToValidate = "txtLimitNum" ErrorMessage = "* The number of people must be a number" validationexpression = "^ [0-9] * $ "> </asp: regularExpressionValidator>
<% -- Control time format -- %>
<Asp: regularExpressionValidator ID = "regular" runat = "server" ValidationGroup = "checkText" ControlToValidate = "txtTime" ErrorMessage = "* the time must be in the format of" validationexpression = "^ (\ d {4 }) -(0 \ d {1} | 1 [0-2])-(0 \ d {1} | [12] \ d {1} | 3 [01]) $ "> </asp: RegularExpressionValidator>
<% -- Verify that the competition location must be a Chinese character -- %>
<Asp: regularExpressionValidator ID = "RegularExpressionValidator4" runat = "server" ValidationGroup = "checkText" ControlToValidate = "txtPlace" ErrorMessage = "* only Chinese characters can be entered at the competition location- \ tags] {0 ,} $ "/>
The above verification only serves as a prompt and does not prevent button addition. Therefore, the validationSummary control should be used to display the verification error message through Messagebox to avoid executing button_click ().
<% -- If the verification fails, the error message (ShowMessageBox = "true") "is displayed in the prompt box -- %>
<Asp: ValidationSummary ID = "ValidationSummary1" ValidationGroup = "checkText" ShowMessageBox = "true" ShowSummary = "false" runat = "server"/>