Field JavaScript Validation (RCS code)

Mindwatering Incorporated

Author: Tripp W Black

Created: 01/06/2006 at 03:43 PM


Notes Developer Tips

Text / Text Area / Select-one / Select-multiple Field Validation:
Updated RCS Code for Form JS Validation Including Select-Multiple Type:


Thanks to Marc of
Rocking Chair Software:

Addition to RCS and MW code to retrieve the JavaScript Control RTF field contents:
if(CheckAllFields() == true) {
GetJSEditorData(); // used with the JS digi JavaScript Control RTF field
_getEditAppletData(); // used with java applet RTF field
//_doClick('$Refresh', this, null); // uncomment to do refresh instead of submit

Addition to RCS and MW code to confirm field exists is below. Add it just below the function start.
function CheckField(field, msg) {
if (field=== undefined) {
// field is missing, abort check
return true;

Addition to RCS and MW code that verifies existence of field before validation for the clear field and check field validation functions. Needed to catch if undefined so that JS doesn't blow up on a missing, misspelled, or expectably hidden by hide-when.

Addition to RCS code that verifies a file upload control has something in its Browse field.
(It does not verify the text is legit if the user hand entered something.)


Additional function to check the value (and Text) of a drop-down selection for validation comparisons:

Radio Button Field Validation:
MW Addition to RCS code to check a Radio Button group:
CheckButton.txtButtonWhichOptionSelected.txt ButtonWhichOptionSelected.txt

MW Addition to set or check a radio button group:

Checkbox Field Validation:
MW Addition to RCS code to check a set of Checkboxes to make sure that at least one of the check boxes are checked.


Better version of checkbox_validation_function.txt that can also handle a single/lone checkbox:
checkbox_with_singlebox_validation.txt checkbox_with_singlebox_validation.txt

MW Addition to RCS code to check if a specific checkbox (value) has been checked.
IsCheckBoxValueMatchedPassedValue.txt IsCheckBoxValueMatchedPassedValue.txt

MW Addition to RCS code to check if any list box item has been selected.

E-mail and Phone Number (dashed: 123-123-1234) Validation:
Validates that an e-mail has a format such as:
Validates phone number for fixed dashed format of 111-222-3333.

EmailAddressPhoneNumber.txt EmailAddressPhoneNumber.txt

Number Field Validation:
Validates that a field contains ONLY numbers (e.g. Positive integer whole numbers).


Validate Field Value Starts With a Matching String - @Begins Equivalent:
function CheckFldBegins(field, chkstr, msg) {
var curstr;
if (field.type=="text" | field.type=="textarea") {
curstr = field.value;
if ( curstr.startsWith( chkstr ) ) {
return true;
} else {
// failure
errorMsgs += msg + "\n\r";
return false;
// not correct type, return true
return true;

previous page