Form validation is a level often encountered in developing WEB applications. Sometimes we have to ensure that certain items in the form must be filled in, must be numbers, must be a specified number of digits, etc. At this time, we need to use form verification. Generally, we commonly use two methods of form verification:
1. Write a JavaScript or VBScript form verification function to verify on the client side;
2. After the form is submitted, use the ASP method Request.Form to get the input value of the form for judgment, and then return the result. This is verified on the server side;
These two methods have their advantages and disadvantages. For example, the first method is faster and usually uses an alert box. The user can quickly complete the form filling in according to the prompts. However, the disadvantage is that the user's browser must be Supports JavaScript scripts, otherwise if he turns off JavaScript, then!@#$%&^* (Oda has fallen to the ground^_^); while the second method has better compatibility, but the disadvantage is speed It is relatively slow (submitted to the server and returned) and inconvenient to use. This time I mainly use JavaScript to verify. Of course, it is safest to use two methods to verify at the same time, but (sweat...) it will make us programmers exhausted:)
The form is explained above For the two methods of verification, let’s talk about the concept of dynamically generating JavaScript in detail. Why do we need to generate it dynamically? Because this kind of client-side verification code is very cumbersome, it would be really tiring if you have to write it yourself every time! Friends who are used to DW (Dreamweaver) or UD may usually use form validation plug-ins. The code generated after use is not artistic, and many of them are unused (code redundancy). What Oda wants to talk about is to generate code that fully conforms to the situation of the form.
Disclaimer: Xiaotian is not proficient in JavaScript. I just want to talk about the dynamic generation method. JS masters can modify it themselves.
Then let’s get started.
1. Let’s first take a look at a simple JavaScript verification code: