Validators
Available validators
Name | XM_FORM_VRULES | Description |
---|---|---|
Text | - | Default setting. The input won't be validated. All characters are allowed. |
Letters & spaces | onlyLetterSp | Only letters (UTF-8) and spaces are allowed, including characters with diacritics (ö, ü, ä, é etc.). |
Letters, numbers and spaces | onlyLetterNumber | Only letters (UTF-8), numbers, and spaces are allowed, including characters with diacritics (ö, ü, ä, é etc.). |
Integer | integer | Only numbers without a decimal point are allowed, such as 100 or -100. |
Positive integer | posinteger | Only positive numbers without a decimal, such as 100 or 200. |
Number | number | Only numbers with a German-style decimal separator (comma) are allowed, such as /100, -4,45 or 1,9. |
Money | money | Only numbers with exactly two decimals places are allowed. The decimal separator is a comma. Thousands separators are not allowed. For example, both 100 and 99,99 are allowed, but not 1,234 or 456.123,23. |
Positive amount of money | posmoney | Same as money, but must not be negative. |
Positive amount of money (opt. decimal) | posmoneyOptionalComma | Same as money, but does not require two decimal place. For example, 3, 3,4, and 3,49 are allowed, but not 3,493. |
E-Mail Validator (International email address,eai) | ||
Date(DD.MM.YYYY) | datumDE | Only German-style dates are allowed, ie. DD.MM.YYYY. Example: 01.01.2015. |
Time | time | Allows only time values of the format hh:mm, such as 01:30 or 13:30. |
Postal code(Germany) | plzDE | Only German postal codes are allowed, ie. five digits such as 01109 or 01069. |
Phone number | phone | Only phone number are allowed. For example, +49 351 810 500, 0049-351-810-500 and 0049/351/810/500 are allowed, but not numbers such as +49 (0)351 810 500 |
URL | url | Only valid URLs are allowed, such as http://www.xima.de , https://www.xima.de , and ftp://ftp.xima.de . |
IP adress | ipv4 | Only IP v4 addresses are allowed, such as 127.0.0.1 and 192.168.0.255. |
Client and server side validation
You can enable sever side validation for all form fields supporting data types. By default, server validation is not enabled. When the user enter an invalid value, the browser checks the form field and displays an error message. However, from a technical point of view, it is still possible to submit forms containing invalid data, such as by sending custom POST requests. By enabling server side validation, all submitted forms will be validated on the server. When they fail to validate, the form will not be accepted and an error will be shown.
Overriding validators
All validators for each data type can be changed by modifying them via Javascript. All validators are contained in the Javascript object window.XM_FORM_VRULES.
To override validators, you can use the script tab of the Xima® Formcycle Designer, or upload a Javascript file on the form's file menu. For example, to change the money validator to accept periods instead of commas as the decimal separator, you can edit the validator as follows.
It is also possible to change the error message that will be displayed, either by modifying the error message directly or by editing the error messages template. Error messages are contained in the Javascript object window.XM_FORM_VRULES. To change the error message for the money validator directly via Javascript, use the following code:
You can also add custom entries to the object XM_FORM_VRULES and XM_FORM_I18N. The name of the entry is the name of the validator. To use this validator to validate an input field, add the HTML attribute vdt to the input field and set its value to the name of the validator.
For example, if you want to add a validator for numbers with at most 5 digits and 2 decimal digits, add the following Javascript code.
XM_FORM_I18N.number_5_2 = "Please enter a number with at most 5 digits and 2 decimal digits.";
Finally, add the HTML attribute vdt to the input field and set its value to number_5_2.
Creating custom validators
errorFunc()
You can create your own validators by using the Xima® Formcycle specific jQuery function errorFunc().
var el = $(this),
var msg = el.attr('name') + ' is not valid';
return (el.val() == 'a') ? msg : '';
}
$('[name=tf1]').errorFunc(getErrorMsg); // Entering the letter "a" into the text field tf1 will show an error.
error()
You can also mark a form field as invalid by using the function error(message).
$('[name=tf1]').error(''); // Removes any error messages from the text field tf1.
Internationalisierung (i18n)
You can customize the error messages in two ways:
- By modifying the global JavaScript object XM_FORM_I18N via the script tab. That object exposes all entries from the i18n variables template.
- In case you want to modify some error messages permanently and for all forms of a client, you should edit the i18n variables templates instead.
To change an error message via JavaScript, such as for the currency, use the following script: