|
Validating Form Input in JavaScript
|
By Amrit Hallan
[Hits: 5855]
|
|
This time we'll make a form that collects information about thevisitor at your site. You must have filled-in copiousregistration forms or survey forms where you had to enter yourname, your email, your address, etc. Sometimes users,intentionally or unintentionally, enter wrong information thatcan either spoil your database scheme or give you lots ofuseless data and hence, waste your precious server space.
To avoid such problems, as much as it can be managed, weprogrammatically try to make sure, that data is entered in anorderly fashion, and no unusable fields are entered. Checkingindividual 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 nonumbers in the Name field [1,2,3,4,.], and in the Email field,no email should be without the "@" sign. We can carry out morecomplex validations, but at the moment, these three shouldsuffice.
/// Remove the extra dots while testing. They have been justinserted so that some email programs don't freak out at thepresence of a JavaScript in the email.
<..script language="JavaScript1.2"> function CheckName(HoldName){ NoNumThere='true'; for(i=0; i
| | |