Field JavaScript Validation (RCS code)

Mindwatering Incorporated

Author: Tripp W Black

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

 

Category:
Notes Developer Tips
JavaScript

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

rcs_javascript_validation_sample.txt

Thanks to Marc of
Rocking Chair Software:
http://www.rockingchairsoftware.com

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
f.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.
ClearFldStyleCheckFieldUpdated.rtfClearFldStyleCheckFieldUpdated.rtf

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.)

CheckFileUpload.txt

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


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:
SetButtonValue.rtfSetButtonValue.rtf


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.

checkbox_validation_function.txtIsACheckBoxFieldChecked.txt

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.
CheckListField.rtfCheckListField.rtf


E-mail and Phone Number (dashed: 123-123-1234) Validation:
Validates that an e-mail has a format such as:
jane.doe@mydomain.com
jdoe@mydomain.com.au
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).

CheckNumberField.txtCheckNumberField.txt

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 ) ) {
field.className="";
return true;
} else {
// failure
field.className="error";
errorMsgs += msg + "\n\r";
field.focus();
return false;
}
}
// not correct type, return true
field.className="";
return true;
}




previous page