Client Validation Script
SOLO Server offers a client validation script which can be used to perform client side validation of form input fields. This can be used with Self Hosted Trial Tracking forms, as an example.
To use this script on a page external to SOLO Server, you must include it in you page using a client side include using the following html code:
<script language="javascript" src="http://secure.softwarekey.com/solo/client_validations.js"></script>
This script contains several functions for validating different data types as follows:
- ValidateDateField - Verifies the input is a valid date.
- ValidateStringField - Verifies the input is a valid string. This basically verifies that no foreign characters are present in the field, as these are not accepted by the SOLO Server database.
- ValidateMoneyField - Verifies the input is a valid monetary value.
- ValidateEmailField - Verifies the input is a validly formatted email address (this does not validate whether the address exists, just whether it is formatted correctly).
- ValidateUSStateField - Verifies the input is a valid 2 character US state code.
- ValidateCAProvinceField - Verifies the input is a valid 2 character Canadian province code.
- ValidateUSPostalCodeField - Verifies the input is a valid US postal code, either a 5 digit zip or zip +4.
- ValidateCAPostalCodeField - Verifies the input is a valid Canadian postal code.
- ValidatePhoneField - Verifies the input is a valid phone number.
- ValidateIntField - Verifies the input is a valid integer value.
- ValidateFloatField - Verifies the input is a valid float value.
Each method has the same input parameters, (oElement, sFieldName, bRequired):
- oElement - The form element to validate.
- sFieldName - The text of the label for the field. This will be displayed on the alert message that pops up if the field does not validate.
- bRequired - A boolean value as to whether the field is required. If set to true and the field is blank, a message will appear asking the user to enter a value in the field. If set to false and the field is blank, validation will succeed.
If a validation for a form element fails, an alert will be popped up to the user with a descriptive error message. Once the user OK's the alert, focus will then be given to field where validation failed.
The validation routines also test the length of the input against the maxlength of the form field if it is defined. This is due to the fact that some automated form fillers are able to populate a form field past it's maxlength. If maxlength is not defined, this checking is bypassed.