Asp. NET validation validation control regular expression special symbols for the description _ Practical Tips

Source: Internet
Author: User

Description of RegularExpressionValidator control expression:

The square brackets "[]" are used with the definition of acceptable characters. [Abc123] indicates that the control can only accept a,b,c,1,2,3 6 characters;

The anti-collection symbol "^" is used to define characters that are not acceptable. [^a-h] means that the control is acceptable except for a to H 8 characters;

The curly brace ' {} ' defines the number of characters that must be entered. {6} indicates that only 6 characters can be entered; {6,} indicates that you must enter more than 6, no upper limit; {2,6} indicates that 2 to 6 characters must be entered, but the curly braces must be placed after the brackets, for example, [A-z]{4} indicates that you must enter any character between 4-bit A and Z.

small dot "." Used to represent any character. For example. {3,6} indicates that 3 to 6 arbitrary characters are accepted.

Vertical Bar "|" The logical symbol used to represent "or". For example [1-9]{3,6}| [A-za-z] {3} indicates that 3 to 6 digits or 3 letters can be accepted. (Can be distinguished by the case)

The Parenthesis "()" is used for chunking, similar to the function of parentheses in numeric operations.

slash "\" if you want the acceptable characters to contain the above special characters. For example \ ([0-9]{3}\), the phone number that represents the input format of "(XXX)".

Code Demo:

Copy Code code as follows:

<%@ Page language= "VB" contenttype= "text/html" responseencoding= "gb2312"%>
<title>validation validation Controls </title>
<body>
<form runat= "Server" >
<p> Enter your name:
<asp:textbox id= "Nam" text= "name" textmode= "Singleline" runat= "Server"/> controltovalidate= "Nam" display= "Dynamic" errormessage= "must enter Name" id= "Rnam" runat= "Server"/></p>
<p> Enter Date:
<asp:textbox id= "Dat" text= "date" textmode= "Singleline" runat= "Server"/> <asp:comparevalidator The correct format for the controltovalidate= "Dat" display= "Dynamic" errormessage= "date is Yyyy-mm-dd" id= "Rdat" operator= "DataTypeCheck" runat= "Server" type= "Date"/> </p>
<p> input Value (integer):
<asp:textbox id= "type" text= "value" textmode= "Singleline" runat= "Server"/> <asp:comparevalidator Controltovalidate= "type" display= "Dynamic" errormessage= "You are not entering an integer" id= "Rtype" operator= "DataTypeCheck" runat= " Server "type=" Integer/> </p>
<p> input Number (1-10):
<asp:textbox id= "num" text= "numeric" textmode= "Singleline" runat= "Server"/> <asp:rangevalidator controltovalidate= "num" display= "Dynamic" errormessage= "can only be the number between 1-10" id= "Rnum" type= "Integer" maximumvalue= "10" Minimumvalue= "1" runat= "Server"/> </p>
<p> Please enter a number less than 50:
<asp:textbox id= "NUM5" textmode= "Singleline" runat= "text=" less than 50/> "Server"
<asp:comparevalidator controltovalidate= "NUM5" display= "Dynamic" errormessage= "The number you enter is not less than" id= "RNUM5" operator= " LessThan "runat=" Server "type=" Integer "valuetocompare="/></p>
<p> Enter a random email:
<asp:textbox id= "eml" text= "email" textmode= "Singleline" runat= "Server"/>
<asp:regularexpressionvalidator controltovalidate= "eml" display= "Dynamic" errormessage= " should be 3-6 any character @2-9 bit any character. 2-3-bit arbitrary character "id=" reml "runat=" Server "validationexpression=". {3,6}@. {2,9}\.. {2,3} "/>
<asp:validationsummary displaymode= "List" headertext= "error message Collection" Id= "tt" runat= "Server"/></p>
<p>
<asp:button id= "But" text= "Submit" runat= "Server"/> </p>
</p>
</form>
</body>

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.