Using ASP for Form Handling: Part 2 - Server Side Form-Field Validation
September 5, 2000
|
Ever need to make sure a user enters data in specific fields on a form, but
did not know how? Ever need to make sure a phone number actually looks like
a phone number? Most of us have and in this article, we will discuss how to
use Microsoft ASP technology to validate data submitted from a form.
|
Introduction
In my last article, I introduced
you to the idea of using Microsoft's Active Server Pages to handle data
submitted from a form on a web page. With that foundation in hand and some
practice, one can create powerful, dynamic web pages. Building on that
foundation, this article will show you how to gather user input from a
web-based form and then test the validity of that input.
Defining Terms
The first thing to accomplish is to make certain that we all understand the
goals that this article aims to achieve. When someone says "form-field
validation," they mean "validating" or checking the data submitted in a
form-field. To be clear, "validation" does not mean making sure that the
submitted data is correct in that it is either true or false (ie. validation
does not check to ensure that someone named John enters his real name in a
form-field. He may enter "Schmoe" or "Cheesehead" as far as the form is
concerned), rather it means to ensure that the data is valid in such a way
that it falls within certain presupposed parameters. Simply put, it means
that when a user is asked to enter their social security number in a field
designated to be a social security number, that they will not enter their
address or dog's name.
If that is unclear, here is an illustrated example to guide you through
that grammatical mess above.
Validation: Incorrect Concept
User's Real Name: "John Doe"
Validation does not make sure that John Doe enters John Doe, the anonymous
nature of the Internet does not give web pages the ability to know and
check a user's name, so Iza Goodboy will go through without question.
Validation: Correct Concept
User's Real Name: "John Doe"
In this case, the web page with form-field validation will catch the fact
that the user entered a number instead of a name (which obviously consists
of characters not numerals). This example correctly illustrates the concept
of form-field validation.
On the next page, we will discuss the first building block of form-field
validation, giving the form a memory.
Even Smarter Forms - Page 2
|