// FormChek.js//// SUMMARY//// This is a set of JavaScript functions for validating input on // an HTML form.////// Many of the below functions take an optional parameter eok (for "emptyOK")// which determines whether the empty string will return true or false.// Default behavior is controlled by global variable defaultEmptyOK.//// BASIC DATA VALIDATION FUNCTIONS://// isDigit (c)                         Check whether character c is a digit // isFloat (s [,eok])                  True if string s is an unsigned floating point (real) number. (Integers also OK.)//// Performance hint: when you deploy this file on your website, strip out the// comment lines from the source code as well as any of the functions which// you don't need.  This will give you a smaller .js file and achieve faster// downloads.//// 18 Feb 97 created Eric Krock//// (c) 1997 Netscape Communications Corporation// VARIABLE DECLARATIONS// decimal point character differs by language and culturevar decimalPointDelimiter = ".";// Global variable defaultEmptyOK defines default return value // for many functions when they are passed the empty string. // By default, they will return defaultEmptyOK.//// defaultEmptyOK is false, which means that by default, // these functions will do "strict" validation.  Function// isInteger, for example, will only return true if it is// passed a string containing an integer; if it is passed// the empty string, it will return false.//// You can change this default behavior globally (for all // functions which use defaultEmptyOK) by changing the value// of defaultEmptyOK.//// Most of these functions have an optional argument emptyOK// which allows you to override the default behavior for // the duration of a function call.//// This functionality is useful because it is possible to// say "if the user puts anything in this field, it must// be an integer (or a phone number, or a string, etc.), // but it's OK to leave the field empty too."// This is the case for fields which are optional but which// must have a certain kind of content if filled in.var defaultEmptyOK = false;// Check whether string s is empty.function isEmpty(s){   return ((s == null) || (s.length == 0));}// Returns true if character c is a digit // (0 .. 9).function isDigit (c){   return ((c >= "0") && (c <= "9"));}// isFloat (STRING s [, BOOLEAN emptyOK])// // True if string s is an unsigned floating point (real) number. //// Also returns true for unsigned integers. If you wish// to distinguish between integers and floating point numbers,// first call isInteger, then call isFloat.//// Does not accept exponential notation.//// For explanation of optional argument emptyOK,// see comments of function isInteger.function isFloat (s){   var i;    var seenDecimalPoint = false;    if (isEmpty(s))        if (isFloat.arguments.length == 1) return defaultEmptyOK;       else return (isFloat.arguments[1] == true);    if (s == decimalPointDelimiter) return false;    // Search through string's characters one by one    // until we find a non-numeric character.    // When we do, return false; if we don't, return true.    for (i = 0; i < s.length; i++)    {           // Check that current character is number.        var c = s.charAt(i);        if ((c == decimalPointDelimiter) && !seenDecimalPoint) seenDecimalPoint = true;        else if (!isDigit(c)) return false;    }    // All characters are numbers.    return true;}/*** Validates a field of type Numeric to ensure that the user has not left it blank* and the number is a float type.** Example call: msg += checkFloatField("document.forms[0]","thatField","That Requried Field");** @param	form  		The name of the form in which the field is located (ex: "document.forms[0]").*		fieldName 	The name of the field you wish to validate.*    		label		The text label on the form that describes the field to the user.** @return	String tmpMsg.  The validation error message.*/function checkFloatField (form, fieldName, label){	var tmpMsg = "";	hasStyle = eval(form + '.' + fieldName + '.style');	val = eval(form + '.' + fieldName + '.value');	// Check to see if a value was entered into the field	if(!isFloat(val))	{		tmpMsg +=" - The field '" + label + "' must contain a numeric value.\n";		if(hasStyle)		{			invalidBorder = "solid 1px red";			eval(form + '.' + fieldName + '.style.border=invalidBorder');		}	}	else	{		if(hasStyle)		{			validBorder = "solid 1px #808080";			eval(form + '.' + fieldName + '.style.border=validBorder');		}	}	return tmpMsg;}