O'Reilly logo

Designing Active Server Pages by Scott Mitchell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating Reusable Server-Side Form Validation Routines

Earlier in this chapter, in Section 5.1.1, we discussed the three common steps taken to create a form:

  1. Create an HTML form with the proper form fields, complete with client-side form validation.

  2. Create a form-processing script and add the needed code.

  3. Add server-side form validation code to the ASP page created in Step 2.

At that time, I mentioned we would look at ways to create robust, reusable code for Steps 1 and 3. Since server-side form validation is paramount to client-side form validation, it makes sense to start by creating code for Step 1. In this section, we will look at how to create a single, reusable ASP page that uses regular expressions to validate form data. In Section 5.5, the discussion will switch to creating a class interface to aid in accomplishing Step 1.

Our reusable server-side form validation routine will exist on the /CODEREUSE/ValidateForm.asp ASP page. (That means every form on our web site will have its ACTION property set to /CODEREUSE/ValidateForm.asp.) This page will contain code that will iterate through the proper collection of the Request object, reading in the value of each form field and determining whether or not the value is valid.

Our validation page, /CODEREUSE/ValidateForm.asp, needs to know what constitutes a valid entry for each and every form field. We’ll supply this information in the NAME property of the form field. Since regular expressions are used to validate form field input, each ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required