Validating Form Input in JavaScript
This time we'll make a form that collects information about the
visitor at your site. You must have filled-in copious
registration forms or survey forms where you had to enter your
name, your email, your address, etc. Sometimes users,
intentionally or unintentionally, enter wrong information that
can either spoil your database scheme or give you lots of
useless data and hence, waste your precious server space.
To avoid such problems, as much as it can be managed, we
programmatically try to make sure, that data is entered in an
orderly fashion, and no unusable fields are entered. Checking
individual fields of the form does this.
We'll see a form here with three fields: Name, Phone and Email.
In this form, no field should be left blank, there should be no
numbers in the Name field [1,2,3,4,.], and in the Email field,
no email should be without the "@" sign. We can carry out more
complex validations, but at the moment, these three should
suffice.
/// Remove the extra dots while testing. They have been just
inserted so that some email programs don't freak out at the
presence of a JavaScript in the email.
<..script language="JavaScript1.2"> function CheckName(HoldName)
{ NoNumThere='true'; for(i=0; i