Analysis on the use of ASP. NET data verification controls

Source: Internet
Author: User

What are ASP. NET data verification controls? What are their functions? Let's take a look,

ASP. NET data verification function:

(1) define the appearance.

(2) display method of the verification program: static or dynamic display.

(3) The group displays an error message.

(4) custom server-side verification.

(5) User-Defined client verification.

(6) regular expression.

The following describes common ASP. NET data verification controls provided in VS2005:

Required: RequiredFiledValidator must be set. Otherwise, you cannot enter the next option.

Compared with a value, CompareValidator compares the value entered by the user with a constant value or a value of a specific data type (greater than, less than, or equal ).

Checks within a certain range: RangeValidator checks user input within the specified upper and lower limits.

Pattern Matching: RegularExpressionValidator checks whether the pattern defined by the regular expression matches. This is often used to check predictable character sequences,

For example, email, phone number, zip code, and so on.

User-Defined: mmvalidator is divided into server-side and client-side verification. We need to write verification rules by ourselves.

Here we will talk about common Regular Expressions (see my regular expression section for details ):

(1) [] is used to specify the characters that can be received. For example, [wuwei] indicates that this control can only receive the characters w, u, e, and I.

(2) ^ is used to define characters that cannot be received. For example, [^ a-e] indicates characters that can be received apart from a to e.

(3) {} defines the number of characters that must be entered. {1,} must be at least one character. [a-o] {5} indicates that five characters are entered between a and o.

(4). represents any character. For example,. {4, 10} indicates that 4 to 10 arbitrary characters are received.

(5) | indicates "logic or ". For example, [1-9] {3, 6} | [A-Za-z] {3} indicates that it can receive 3 to 6 digits or 3 letters.

(6) () is used for chunking, similar.

(7) \ escape characters. For example, \ ([0-9] {3} \) defines the parentheses of the three numbers.

Although we can use many of the original regular expressions in the ASP. NET data validation controls that come with VS2005, there are still a lot to write by ourselves. I was wondering, "Why does Microsoft not provide a function for adding regular expressions by ourselves? In this way, we only need to input all the commonly used expressions with the mouse, unfortunately, this is not the case! "In this case, we need to use the isMatch method of the Regex class to customize the regular expression. For example, many backend users must enter their own database names when logging in to prevent unauthorized users from logging in. The verification process is as follows:

 
 
  1. Protected VoidPage_Load (object sender, EventArgs e)
  2. {
  3. }
  4. Public BoolValidateTable (string str)// When calling the Regex class, the using System. Text. RegularExpressions namespace must be introduced. 
  5. {
  6. ReturnRegex. IsMatch (str ,@"^ (\ W + $) | ^ ([\ u4E00-\ u9FA5] {0,} $ )");
  7. }
  8. Protected VoidButton#click (object sender, EventArgs e)
  9. {
  10. If(! ValidateTable (TextBox1.Text ))
  11. {
  12. Response. Write ("<Script> alert ('invalid data table name' you entered) </script>");
  13. }
  14. }

The content of the ASP. NET data verification control is introduced here. I hope you can understand the ASP. NET data verification control through this simple explanation.

  1. Implement ASP. NET data encryption using symmetric encryption algorithms
  2. ASP. NET data import implementation Excel to MSSQL
  3. Example of ASP. NET dataset usage
  4. Analysis on ASP. NET data type conversion
  5. Analysis of validation groups in ASP. NET data verification

Related Article

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.