Check if filling is correct in ASP + FORM

zhaozj2021-02-16  58

Check if filling is correct in ASP FORM

Author: Wawe Time: 2002-9-28 Recommended Level: ★ View author information and author anthology

Compilation: Today's business website, or personal website, how many customers have a customer investigation, something that users registration, will inevitably use the form, the filling of these forms is correct, obviously controlled by handwriting code of. I admit that writing code is an interesting job. However, every verification form comes to handwritten code, we want to improve our work efficiency, not to spend our very limited time to spend the verification work of the form. Based on some reasons, the web application is very bad to verify the user's input. HTML 3.2 specification allows you to control users' feedback, but malicious or technically superb users can bypass, so even the browser-ended handwritten code, The server side also needs to be verified to ensure security. Here is Microsoft staff, giving the business website with handwritten code control form validation. 1. Although error messages or icons are often adjacent to the input elements, they are almost always located in different cells. 2. There is often a region in the page to summarize all errors. 3. Many sites contain client scripts to provide faster feedback while preventing rounds with the server in white. 4. Many sites that contain client scripts will display the information box when an error occurs. 5. Not only will the text input, but also verify the drop-down list and the radio button. 6. If a field is empty, the site usually displays different information or icons when the entry is invalid. 7. Many effectiveness checks can replace common expressions well. 8. Verification is usually based on two input comparisons. 9. 90% or more verification tasks is some common operations, such as check names or postal codes. Most sites seem to still be repeated. 10. Because the difference between the site is usually too big, a perfect solution cannot be obtained to handle all verification tasks for each site. If you want to confirm that you have a very "cool" method, you can ban you enter null values ​​in the name field, remember to choose ASP.NET, and look at the tutorial below. ASP.NET Form Verification Procedure 1. ASPX file is compiled, run 2. User Enter Data 3. Trigger Page_Load Event 4. Change the Web Control Properties, no input 5. No input 5. Return the page to users 6. Remind the user to enter the Page_Load Procedure Page Object contains some important properties and methods related to server-side verification. The following table lists all Collect and Methed of the Page_Load property. Page_Load method name Description Isvalid (most often) This is the most useful attribute. This property can check if the entire form is valid. This check is usually performed before updating the database. Only all objects in the Validators set are all valid, this property is true and does not store this value into the cache. Validators This page All validation objects are set. This is a collection of objects that implement the IVALIDATOR interface. Validate is called when verifying. The default execution method on the PAGE object is to each validator and require each verifier to evaluate it. Used to verify the list of validates (Web Control) RequiredFieldValidator checks if the user enters or selects any content REGULAREXPRESSIONVALIDATOR to check the user input according to the rule expression. This process allows many types of inspections that can be used for postal coding and telephone numbers. CompareValidator compares the input control with a fixed value or another input control. For example, it can be used in the password verification field. It can also be used to compare the date and numbers of the input.

RangeValidator is very similar to CompareValidator, just it is used to check if the CustomValidator between the values ​​of two values ​​or other input controls allows users to write their own code to join the verification frame. Example Description The operation of the controls described above will establish a minimized .aspx page, we don't need gorgeous modifications.

Please enter a new user ID and password

User ID
password
please Re-enter the password
The program is a very harsh thing, so it is necessary to emphasize all items, we can do this. Add RequiredFieldValidator before each field. If the input field is empty, we have to display an asterisk (*) before the field and report an error next to it. For example:
* User ID: < TD> No content is entered, then "*" is displayed next to the tag. An error message appears. The "ControlTovAlidate" property specifies the control ID that needs to be verified. The final step is to display all the error phenomenon to the top of the page.

Code: then we need the user ID must be 6-10 characters, the password must be 4-12 letters, and must have @ # $% ^ & */character of. Code: Here we increase the limitations of ID lengths.

then we want to verify that the passwords input twice are the same. By default, CompareValidator only makes simple string matching comparisons. If desired, it can make more complex comparisons involving dates and numbers. Several questions Need to pay attention to the script library because the Web control script is in the script library, so you don't have to send all the client authenticated code directly to the page, although it seems to do so. The main script file is similar to the following: