Asp.net verification controls for people

Source: Internet
Author: User


ASP. NET is a web development tool launched by Microsoft. It has powerful functions. Today, I watched the video and talked about the verification control. I really felt that Microsoft has served the people wholeheartedly. More and more admire Microsoft, people are designed, we must use it, otherwise too ...... Now let's take a look at the validation controls of ASP. NET and feel the powerful functions of ASP. NET.

 

The following describes the six authentication controls of ASP. NET.

 

Verification type

Controls used

Description

Required field verification

Requiredfieldvalidator

Make sure that the user does not skip an input.

Comparison Verification

Comparevalidator

Compare user input with a constant value, another control, or a value of a specific data type (using comparison operators such as less than, equal to, or greater ).

Range Verification

Rangevalidator

Check whether the user input is within the specified upper and lower limits. You can check the range of number, letter, and date pairs.

Regular Expression Verification

Regularexpressionvalidator

Check whether it matches the pattern defined by the regular expression. This type of verification allows you to check the character sequences in predictable character sequences, such as email addresses, phone numbers, and postal codes.

Custom Verification

Customvalidator

Use your own verification logic to check user input. This type of verification allows you to check the value that is generated at runtime.

Verification Summary

Validationsummary

Displays verification errors for all validators on the page as a summary.

 

1. Use of requiredfieldvalidator (field verification is required)

 

The Code is as follows:

 

<Asp: requiredfieldvalidatorid = "validator_name" runat = "server" controltovalidate = "Control name to be checked" errormessage = "error message" display = "static | dymatic | none"> placeholder </ASP: requiredfieldvalidator>

Code Description:

 

  • Controltovalidate: indicates the ID of the control to be checked;
  • Errormessage: indicates the error message when the check is invalid;
  • Display: Display Mode of the error message. Static indicates that the error message of the control occupies a certain position on the page. dymatic indicates that the page control is occupied only when the control error message appears; none indicates that the error is not displayed when it appears, but it can be displayed in validatorsummary;
  • Placeholder: indicates that when the display is static, the error information occupies the page space as large as the "Placeholder ".

 

2. comparevalidator Control

 

The Code is as follows:

 

<Asp: comparevalidatorid = "validator_id" runat = "server" controltovalidate = "Control ID to be verified" errormessage = "error message" controltocompare = "Control ID to be compared" type = "string | integer | double | datetime | currency "operator =" equal | notequal | greaterthan | greatertanequal | lessthan | lessthanequal | datatypecheck "display =" static | dymatic | none "> placeholder </ASP: comparevalidator>

 

Code Description:

 

  • Controltovalidate: indicates the ID of the control to be checked;
  • Errormessage: indicates the error message when the check is invalid;
  • Controltocompare: the ID of the control to be compared;
  • Type indicates the Data Type of the control to be compared;
  • Operator indicates a comparison operation. Here, there are 7 Comparison Methods: greater than, less than or equal ......;
  • Display: Display Mode of the error message. Static indicates that the error message of the control occupies a certain position on the page. dymatic indicates that the page control is occupied only when the control error message appears; none indicates that the error is not displayed when it appears, but it can be displayed in validatorsummary;
  • Placeholder: indicates that when the display is static, the error information occupies the page space as large as the "Placeholder ".

 

 

3. rangevalidator Control

 

The Code is as follows:


<Asp: rangevalidatorid = "vaidator_id" runat = "server" controltovalidate = "Control ID to be verified" type = "integer" minimumvalue = "minimum" maximumvalue = "maximum" errormessage = "error message" display = "static | dymatic | none"> placeholder </ASP: rangevalidator>

 

Code Description:

 

  • Type: to define the type of the input value of the control;
  • Minimumvalue: defines the minimum value of the input value of the control;
  • Maximumvalue: defines the maximum value of the input value of the control;
  • Operator indicates a comparison operation. Here, there are 7 Comparison Methods: greater than, less than or equal ......;
  • Display: Display Mode of the error message. Static indicates that the error message of the control occupies a certain position on the page. dymatic indicates that the page control is occupied only when the control error message appears; none indicates that the error is not displayed when it appears, but it can be displayed in validatorsummary;
  • Placeholder: indicates that when the display is static, the error information occupies the page space as large as the "Placeholder ".

 

 

Iv. regularexpresionvalidator (Regular Expression) Control

 

The Code is as follows:


<Asp: regularexpressionvalidatorid = "validator_id" runat = "server" controltovalidate = "Control name to be verified" validationexpression = "Regular Expression" errormessage = "error message" display = "static"> placeholder </asp: regularexpressionvalidator>

 

In the above standard code, validationexpression (Regular Expression) is the focus. Now let's take a look at its construction:

 

In validationexpression, different characters indicate different meanings:

 

1

[……]

Match any character in the brackets

2

[^…]

Match any character not in parentheses

3

\ W

Match any character (~ Z, ~ Z and 0 ~ 9)

4

\ W

Match any blank character

5

\ S

Match any non-blank character

6

\ S

Match any non-word characters

7

\ D

Match any number (0 ~ 9)

8

\ D

Match any non-digit (^ 0 ~ 9)

9

[\ B]

Match A backspace key character

10

{N, m}

Matches the previous expression at least N times, and the maximum is m times.

11

{N ,}

Match the previous expression at least N times

12

{N}

Exactly match the previous expression n times

13

?

Match the previous expression 0 or 1 time {0, 1}

14

+

Match the previous expression at least once {1 ,}

15

*

Match the previous expression 0 at least {0 ,}

16

|

Match the preceding or following expression

17

(...)

Combine projects in a unit

18

^

Match the start of a string

19

$

Matches the end of a string

20

\ B

Match character Boundary

21

\ B

Match a location with a non-character Boundary

 

 

V. customvalidator Control

 

The Code is as follows:


<Asp: customvalidatorid = "validator_id" runat = "server" controltovalidate = "control to be verified" onservervalidatefunction = "verification function" errormessage = "error message" display = "static | dymatic | none"> placeholder </ASP: customvalidator>

 

In the above Code, you must define a function to verify the input.

 

6. validationsummary Control

 

The Code is as follows:


<Asp: validationsummaryid = "validator_id" runat = "server" headertext = "header information" showsummary = "True | false" diaplaymode = "list | bulletlist | singleparagraph"> </ASP: validationsummary>

 

Code Description:

 

  • Headtext is equivalent to the headtext of the table,
  • Displaymode: Display Mode of error messages. List is equivalent to <br> in HTML; bulletlist is equivalent to <li> in HTML; singleparegraph indicates that error messages are not separated;

 

ASP. net verification control is introduced to you. familiar with using these controls will really help you a lot, save time and improve efficiency. With these controls, it will not appear when you are not easy to write the subject of the data submission program, we have to spend a lot of time verifying whether every user input is in combination.

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.