Validate |
Enables client side validation to the Web pages.
Syntax
HTML |
<div cordysType="wcp.library.util.Validate" id="validateID"> <div> ... </div> </div> |
Scripting | application.addLibrary("cordys/wcp/library/util/validate.htm",validateID) |
The component can also be added to any HTML element in the Web page by specifying the class attribute of the HTML element:
HTML | <ELEMENT class="validate" id=elementID></ELEMENT> |
The validate library provides an easy, declarative way to add client side validations to Web pages. For each static element on the page with the attributefieldTypeset, validation is added.
To dynamically add and initialize this component, you can use theinitializeHTMLElements()oraddType()methods of the Application object.
The following table lists the properties and methods can be defined for the component.
Table 1. List of Attributes
Attribute | Property | Description |
---|---|---|
calendar | calendar | String that denotes the unique identifier of the element that contains the calendar behavior. |
charactercase | charactercase | String that specifies the case that the characters in string fields should be converted to. The possible values are: |
upper | String fields will be converted to UPPER case. | |
lower | String fields will be converted to LOWER case. | |
calendar | calendar | String that specifies the delimiter for float and amount field types. |
displayFormat | displayFormat | String that specifies a special format with which the value can be displayed. |
expression | expression | String that specifies a piece of script that can be evaluated against the value specified in the entry. |
fieldType | fieldType | String that specifies the type of field. The property decides whether the element to which it is attached, needs to be validated or not. If this is not specified, then the validate component leaves the element, while validation. This can take the following possible values: |
text | The field can accept any type of strings. | |
integer | The field can accept integers values, and can be signed / unsigned depending upon thesignedproperty. | |
float | The field can accept all decimal values, and can have a delimiter depending upon thedelimiterproperty. It is 32-bit floating point type. | |
amount | The field can accept any currency values, which depends onsignedanddisplayFormatproperties. | |
date | The field can accept dates specified bydisplayFormatproperty and on the locale settings on the computer. | |
The field is of type mail, which can accept any mail IDs. | ||
utext | This field accepts any type of string that has UTF-8 characters. | |
double | The field accepts all decimal values, and can have a delimiter depending upon the delimiter property. It is 64-bit floating point type. | |
hexBinary | This represents arbitrary hex-encoded binary data. | |
base64Binary | This represents Base64-encoded arbitrary binary data. | |
anyURI | This represents a Uniform Resource Identifier Reference (URI). | |
filter | filter | String that specifies the characters that are allowed or not allowed in the field. |
help | help | String that specifies the URL to a file that contains help information about the particular field that is currently in focus. Once thehelpattribute is set to a field, the help can be invoked by pressing F1. For this to happen, the focus should be set on the corresponding field for which the information is required. If an empty URL is specified, then the help information will be removed for that particular field. This property can be used without declaring thefieldTypeproperty. |
mask | mask | String that specifies the mask that allows to define an expected format for a given field. |
maxValue | maxValue | String that specifies the maximum value that the field can have. ThemaxValueproperty includes the boundary value also as the limit. For example, if maxValue is 10, then validation is done inclusive of 10. The property can be set for fieldTypes integer, float and amounts only. Also,maxValuecan accept only integer values. If a float is given for validation, it fails to validate the decimal points. Applicable field types include float, double, decimal, integer, amount. |
minValue | minValue | String that specifies the minimum value that the field can have. TheminValueproperty includes the boundary value also as the limit. For example, if minValue is 10, then validation is done inclusive of 10. The property can be set for fieldTypes integer, float and amounts only. Also,minValuecan accept only integer values. If a float is given for validation, it fails to validate the decimal points. Applicable field types include float, double, decimal, integer, amount. |
msg | msg | String that specifies the error message that can be displayed instead of the default message when an error occurs. |
regExpr | regExpr | String that specifies the filter that is to be used for validating the field, but in a regular expression format. |
required | required | Boolean that indicates whether the field can be left empty or is required to be entered. The property can be used to avoid giving null entries to the field. However, if required is set to true, then the control does not move to the next control unless data is entered in it. In order to give flexibility to this property, this in combination with thevalidationLevelproperty ensures that the field is checked for null entries on the spot or when the page is unloaded. |
signed | signed | String that specifies whether + and - signs are permitted to be used in integer, float and amount fields. |
tooltip | tooltip | String that specifies the text / HTML that can serve as a tool tip on the field. |
validationLevel | validationLevel | String that denotes the level of validation that can be performed on the field. |
minLength | minLength | String that represents the minimum length of the value. The applicable field types are text, hexBinary, base64Binary, anyURI. |
maxLength | maxLength | String that denotes the maximum length of the value. Applicable field types are text, hexBinary, base64Binary, anyURI. |
provide minLength = maxLength | provide minLength = maxLength | String that specifies minLength=maxLength. Applicable field types are text, hexBinary, base64Binary, anyURI. |
whitespace | whitespace | String that allows following three parameters:
|
maxExclusive | maxExclusive | Boolean that indicates whether themaxValueis exclusive. Applicable field types are float, double, decimal, integer and amount. |
minExclusive | minExclusive | Boolean that indicates whether theminValueis exclusive. Applicable field types are float, double, decimal, integer and amount. |
totalDigits | totalDigits | String that denotes the maximum number of digits in the value. Applicable field type is decimal. |
fractionDigits | decimal | String that denotes the maximum number of digits in the fractional part of the value. Applicable field type is decimal. |
Table 2. List of Methods
Method | Description |
---|---|
add | Registers the specified element to the validate component. |
checkAllFields | validates all the fields in the page and returns a Boolean indicating whether all the fields are validated or not. |
reload | Searches the whole document for new elements to be validated, and registers the new elements that has the "fieldType" property set. |
Sets given property on source element with the specified value and validates it. |
Example
This sample shows the use of the validate library.
<!DOCTYPE HTML PUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title></title> <script type="text/javascript" src="/cordys/wcp/application.js" ></script> <script type="text/javascript"> function checkAll() { if (validate.checkAllFields() == true) window.application.notify("Validation check complete. Everything ok"); } </script> </head> <body> <div cordysType="wcp.library.util.Validate" id="validate" automatic="false" async="false" style="display:none"></div> <h5>Validation Demo</h5> <table> <tr> <td>Integer :</td> <td><input class="input" fieldType="integer" minValue="10" maxValue="100"/></td> <td>(Value between 10 and 100)</td> </tr> <tr> <td>Float :</td> <td><input class="input" fieldType="float" required filter="[0-9.,+-]"/></td> <td>(Required field)</td> </tr> <tr> <td>Amount :</td> <td><input class="input" id="amount" value="193.2745" fieldType="amount" signed="true" filter="[0-9.,+-]" regExpr="^[-+]?\d+(\.\d{4})?$" msg="Please specify an amount with 4 decimals" /></td> <td></td> </tr> <tr> <td>Integer :</td> <td><input id="int" class="input" fieldType="integer" signed="true" filter="[0-9+-]" expression="parseFloat(int.value) > parseFloat(amount.value)" /></td> <td>(Should be larger than previous field)<br></td> </tr> <tr> <td>Capitals :</td> <td><input id=cfield class="input" fieldType="text" maxLength="4" filter="[A-Za-z ]" required charactercase="upper"/></td> <td>(Required field)</td> </tr> <tr> <td colspan=3 align="left" ><br><button class="medium" onclick="checkAll()" >Check All</button></td> </tr> </table> </body> </html>