Quick Search for:  in language:    
script,combination,common,form,validation,ele
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
Java/ Javascript Stats

 Code: 220,465. lines
 Jobs: 92. postings

 How to support the site

 
Sponsored by:

 
You are in:
 
Login





Latest Code Ticker for Java/ Javascript.
Click here to see a screenshot of this code!vok - The vocabulary trainer
By Thorsten Stärk on 1/7

(Screen Shot)

Java, Calculator
By Rockwell on 1/4


Eatable Interface
By Rockwell on 1/4


Superclass Person
By Rockwell on 1/4


Draws Cube Function
By Rockwell on 1/4


Rectangle Class
By Rockwell on 1/4


Find Number of Upper and Lower Case Letters in a Command Line Argument String
By Rockwell on 1/4


anagrams
By Rockwell on 1/4


Text Reader with Tokenizer
By Rockwell on 1/4


Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!

Affiliate Sites



 
 
   

Complete, general form validation

Print
Email
 
winzip icon
Submitted on: 5/8/2000 12:46:19 PM
By: Eric H. Anderson 
Level: Intermediate
User Rating: By 5 Users
Compatibility:JavaScript

Users have accessed this code 20727 times.
 
 
     This script is a combination of a lot of common form validation elements - checking for non-entries, image swaping to indicate invalid entries, focusing on invalid fields, and feedback to the user through an alert box. I got tired of writing new code for every form (or even cutting and pasting a lot) so this is intended as a .js include file, and all the information necessary to validate the form is contained in the form itself. Most validation is of the did-they-fill-it-in variety. See the comments in the script for more details. Additional validation can be performed with a customized object-oriented JavaScript function. Explanations and an example are provided in the comments.
 

HTML:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!

//**************************************
//     
//HTML for :Complete, general form valid
//     ation
//**************************************
//     
<HTML>
<HEAD>
// the actual JS code is downloadable be
//     low.
// it should be used as a .js include fi
//     le
// this HTML is simply to provide an exa
//     mple of the form structure required
// <script language="javascript" src=
//     "errorCheck.js">
</HEAD>
<BODY>
<FORM name="Fred" action="YOUR.COM/PATH.HTM" method="post" onSubmit="return errorCheck(this, 'path.to.clear.dot.gif', 'path.to.red.star.gif', false);">
<INPUT type="password" name="up_req_userpassword">
	 <INPUT type="password" name="conf_userpassword">
	 <INPUT type="hidden" name="mes_userpassword" value="Please make sure that you have entered a password, and typed exactly the same way again in the confirmation box.">
</FORM>
</BODY>
</HTML>
winzip iconDownload code

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.

Virus note:All files are scanned once-a-day by Planet Source Code for viruses,but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:
1)Re-scan downloaded files using your personal virus checker before using it.
2)NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

If you don't have a virus scanner, you can get one at many places on the net including:McAfee.com

 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this code(in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
5/8/2000 1:27:55 PM:Matt
This is some solid code, and frankly it 
makes my life a lot easier since I'm no 
JS wizard.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
10/10/2002 12:19:16 PM:ckyweriga
Code lookes great. I am just about to 
ad this to my form to validate 
everything. I do have one request 
however, I am not that great at JS so 
if you could please help me add a 
section where I could stop some people 
from using sertain email address from 
like themail.com etc.. I already have 
code for this but I would like to add 
this to your code. If you could do this 
for me, I will send you this code I got 
and then maybe you can implement this 
in to yours...
Hope to hear from you 
soon.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
11/7/2002 7:50:18 PM:Eric H. Anderson
I'd recommend (off the top of my head) 
modifying the checkEmail function. Add 
a JavaScript Array that contains the 
bad domains. Then in the "else" section 
of the if clause, instead of just 
returning true, loop through the array, 
and compare the domain portion of the 
entered address to the current values 
in the array. You should be able to get 
the domain portion using the indexOf 
and substring methods.  
If you find 
a bad domain, return false, otherwise, 
go ahead and return true after the loop 
on the bad domain array is 
complete.
you'd end up with 
something like
var aryBadDomain = 
Array('not.me','bad.com');
for 
(i=0;i<aryBadDomain.length; i++){
 if 
(aryBadDoman[i] == strFormEmailDomain) 
{
    return false;
  }
}
Or you 
could use a regular expression to do a 
much more complex filter on the domain.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
12/16/2002 7:54:03 AM:Josef
what exactly are the checkbox and 
checkselected functions checking.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | Java/ Javascript Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.