The Asp.net regularexpressionvalidator control verifies that the input value matches the pattern specified by the regular expression.

Source: Internet
Author: User

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"/>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.