Script to check a form is filled out correctly
                      Written by Mark Wilton-Jones, 1/1/2002
      v1.0.2 Updated 29/09/2005 to allow Norwegian characters (uses utf-8 encoding)

Please see http://www.howtocreate.co.uk/jslibs/ for details and a demo of this script
Please see http://www.howtocreate.co.uk/jslibs/termsOfUse.html for terms of use

To use this, insert the following into the head of your document:

<script src="PATH TO SCRIPT/formcheck.js" type="text/javascript" language="javascript1.2"></script>
<script type="text/javascript" language="javascript1.2"><!--

//You can adjust this bit here to suit your purposes. I have given an example of its use

function someFunctionYouCreated( theForm ) {
	if( !isValidType( theForm.title, 'select' ) ) {
		window.alert( 'You have not selected a title.' );
		return false;
	if( !isValidType( theForm.firstName, 'name' ) ) {
		window.alert( 'You have not given a valid first name.' );
		return false;
	if( !isValidType( theForm.lastName, 'name' ) ) {
		window.alert( 'You have not given a valid last name.' );
		return false;
	if( !isValidType( theForm.email, 'email' ) ) {
		window.alert( 'You have not given a valid email address.' );
		return false;
	if( !isValidType( theForm.phoneNum, 'number' ) ) {
		window.alert( 'You have not given a valid phone number.' );
		return false;
	return true; //don't forget this line


the form might contain the following attribute:
onsubmit="return someFunctionYouCreated(this);"

Datatypes that can be tested for are:
'select' - checks that something other that option 0 on a select box has been chosen
'name' - checks that a valid name type has been given, ie. me, henry, anne-marie, billy-joe-sue
'email' - checks that a valid email type has been given
'number' - checks that all characters given are numbers

Note, the email address check is not perfect. The correct pattern is far too much for some browsers
to handle, which is why I did not use it, but here it is if you want it:

function isValidType( oInput, oType ) {
	switch( oType.toLowerCase() ) {
		case 'select':
			return oInput.selectedIndex;
		case 'number':
			if( !oInput.value ) { return false; }
			for( var mXi = 0; mXi < oInput.value.length; mXi++ ) {
				if( oInput.value.charAt( mXi ) != '' + parseInt( oInput.value.charAt( mXi ) ) + '' ) { return false; }
			} return true;
		case 'name':
			return ( oInput.value && !oInput.value.replace( /[a-záàäçéèêñóòôöüæøå]+( ?[-']?[a-záàäçéèêñóòôöüæøå]+)*/i, "" ) );
		case 'email':
			return ( oInput.value && !oInput.value.replace( /[\w\-\+]+(\.[\w\-\+]+)*@([\w\-áàäçéèêñóòôöüæøå]+\.)+[a-z]+/i, "" ) );