Website Design Table Verification (ASP)

xiaoxiao2021-03-06  67

The general dynamic website needs to collect user information through a form, or interact with the user, although we believe in the vast majority of people have chosen

The form will be carefully completed, but it is not possible to avoid the boring people to fill the form.

Fill in errors, or they forget to fill in some options. In order to avoid this, developers will add a verification process to form data to form data.

Before or before the server verifies the data fill in the user, if you encounter an error, return to request the user to correct. Cranes in ASP are usually doing this: 1. Verify with JavaScript on the client. 2. Verify with VBScript on the client. 3. Verify with VBScript on the server side. The above mentioned two different environments, server-side and clients, client authentication actually included in the downloaded page, when the user submits the form

Waiting, it is verified directly in the local page that has been downloaded to a local page, which can reduce the server end. The server-side verification is

The page is submitted to the server processing, and the other ASP page on the server will execute the verification of the form before returning the result to the client. Such a disadvantage is that each

Once verified, you have to pass the server and the time is longer. But using server-side verification can achieve better verification. This article is to tell the verification of the server side in the ASP. Before you understand the following introduction methods, you need to think about what you need to be controlled in the form verification problem. Just like software engineering ideas

When you analyze what kinds of respect should be verified. 1. Require the user's input must be Chinese (English or number). 2, require the user's input must be a valid email address. 3. Various different limits for the data entered by the user. 4. Limit the amount of data input by the user. 5, .... In fact, we will encounter many different problems in the site design, and we need to define some regulations and restrictions. Below we will tell the verification method in an example. 1. Verify the number of inputs to assume a text box

'Require users to enter numbers

IF not isnumeric (Request.form ("TextField")).

Response.write "re-filled"

END IF

'Request to limit the number length, if you want to enter the OICQ number

'This example limits the user's input only to 4 to 10 digits

IF LEN ("TextField")> 10 or Len (Request.form ("TextField")) <4 THEN

Response.write "re-filled"

END IF

Of course, the same is the same as Request.Form and Request, just how you wrote it.

2. Verify the email address entered by the user

'Reference a generic detection function

'Due to the longer test procedure, it is called to call it as a function.

Function isvalidemail (email)

DIM Names, Name, I, C

'Check for Valid Syntax in An Email Address.

Isvalidemail = true

Names = split (email, "@")

IF Ubound (Names) <> 1 TeniDemail = False

EXIT FUNCTION

END IF

For Each Name in Names

IF len (name) <= 0 THEN

Isvalidemail = false

EXIT FUNCTION

END IF

For i = 1 to len (name)

C = LCase (MID (Name, I, 1))

IF INSTR ("AbcDefghijklmnopqrStuvwxyz_-.", c) <= 0 and not isnumeric (c) THEN

Isvalidemail = false

EXIT FUNCTION

END IF

NEXT

IF LEFT (Name, 1) = "." or right (name, 1) = "." THEN

Isvalidemail = false

EXIT FUNCTION

END IF

NEXT

IF INSTR (Names (1), ".") <= 0 THEN

Isvalidemail = false

EXIT FUNCTION

END IF

I = LEN (Names (1)) - Instrrev (Names (1), ".")

IF i <> 2 and i <> 3 THEN

Isvalidemail = false

EXIT FUNCTION

END IF

IF INSTR (Email, "..")> 0 THEN

Isvalidemail = false

END IF

END FUNCTION

'The above functions you should understand, of course, you can modify this code so that even if the user enters

XXX@ccc.ddd is an error message address

Because DDD is not a valid domain name. 'You can write this time when you quote

IF IsValidemail (Trim ("TextField"))) = false

Response.write "re-filled"

END IF

3. Verify the empty form unit

Some information is requested that the user must fill it, so it is not allowed to be empty, so it is necessary to prompt when the user is input.

'Treatment of empty unit

If Request.form ("TextField") = "" "" "

Response.write "filled in empty"

END IF

4. What is the user's input is not a date?

First understand the date value format 2002-11-19

'Direct judgment is a date

if not isdate (Request.form ("TextField")).

Response.write "Date Fill in"

END IF

And we often use three drop-down frames at the design website to implement the year, month, day three different options, how to link these three values ​​and verify

? First of all, I must establish three pull-up boxes, named the table named Date, Month, Year, and then the background processing, because we have previously at the front desk

Get the three passages of Date, Month, Year, so we must connect them to synthesize a variable to verify and deposit into the database. even

It can be written like a standard date format expression:

Birthday = trim (Request.form ("Year") & "-" & Trim ("Month") & "" "& TRIM (Request.form (" Date ") Verify that the converted input is The legal date can be used using the isdate function:

IF not isdate (birthday) THEN

Response.write "error"

END IF

5. Do not allow users to enter certain special characters here We assume that the value passed is Content, we don't allow the input value to be = and%

If INSTR (Request ("=")> 0 or Instr (Request ("Content"), "%")> 0

THEN

Response.write "can't enter = and%"

END IF

In fact, we can also write a lot of verification functions. I just listed one or two, I hope to help everyone.

转载请注明原文地址:https://www.9cbs.com/read-110443.html

New Post(0)