Uniform Mail : Validation

Although version 2.0 onwards of the main perl program can perform validation, javascript is more suited to this task. Therefore, a sophisticated generic validator written in javascript is included. The script file is named uniformmail.js. Use of this script is explained below.

Main Features

checkbox

Validation fails if the box is not checked.
Typically, the text should read I agree to the terms above.

password

Validation fails if the number of characters entered is less than the minimum.
The default minimum is 6.
If two password fields have the same name, they must be identical.

radio

Validation fails if no button in the group is checked.

select-one

Validation fails if the selected index is zero or the selected item is blank or the selected item begins and ends with a hyphen ('-' character).

select-multiple

Validation fails if no items are selected.

text

Text fields can be treated as integers or email fields. See below.
If two text fields have the same name, they must be identical.

textarea

Validation fails if the number of characters entered is less than the minimum.
The default minimum is 1.

Calling the Validation Script

 



txConfirm
These text controls have the same name, therefore they must contain the same data.
This works for password fields too.




rbGender
Radio buttons and checkboxes should always be wrapped in labels to ensure browser compatibility when highlighting.



ckAgree
If validated, checkboxes must be checked.



password
The default minimum length is 6. No other checks are performed.



file
Treated as a text field. Currently, Uniform Mail cannot accept uploaded files.



txEventTest
Whenever a key is pressed, an alert box is displayed.



soDays
The first item is always invalid as are blank items and items that begin and end with '-'.



smCars
At lease one item must be selected.



txTest
This control has no label therefore it is highlighted if invalid.


 onclick="ufm_unhighlightControls(document.forms[0],true)"
A reset button restores all fields within a form to their default values.
Uniform Mail provides a function to clear highlighting on the specified form. If true is also passed, the first control is focused.

 ufm_validate(document.forms[0])
Validate all fields. No special rules apply.

 ufm_validate(document.forms[0],'!','ckAgree')
Validate all fields except ckAgree. No special rules apply.
When '!' is passed as the first name parameter, the named fields that follow are excluded from verification (unless prefixed).

 ufm_validate(document.forms[0],'!','ckAgree','#txTest')
Validate all fields except ckAgree. Treat txTest as a hexadecimal integer field.

 ufm_validate(document.forms[0],'@txTest','rbGender')
Validate only the specified fields. Treat txTest as an email field.

 ufm_validate(document.forms[0],'@?txTest','rbGender')
Validate only the specified fields. Treat txTest as an optional email field.

 ufm_validate(document.forms[0],'[12]txTest','rbGender')
Validate only the specified fields. The field txTest must contain at least 12 characters.

 ufm_validate(document.forms[0],);
Conduct your own test. Be certain that all parameters are enclosed within quotes and separated by commas.

Validating Custom Controls

If you require a validation or highlight method that is not provided by the standard script, it can be added very easily. You simply need to create the method and assign it to the control.

<input type="text" name="custom" id="custom">

<script type="text/javascipt">
<!--

function validateCustom(pfc)
// pfc is the prefix code : see function ufm_getPrefixCode.
{ return (this.value.toLowerCase() == 'ok') }

function highlightCustom(hl)
// If hl is true, highlight must be set, if false it must be cleared.
{ if (hl) this.style.color = '#0000FF'; else this.style.color = '' }

// Locate the custom control and assign the handlers.
// Note that the event names ‘ufm_on...’ are entirely lower case.
var c = document.getElementById('custom');
if (c) {
  c.ufm_onvalidate  = validateCustom;
  c.ufm_onhighlight = highlightCustom;
}

// -->
</script>