|
Validation types allow you to validate data that users enter on
the add/edit page. You can use standard
validation types or create your own validation
plugins. If field value doesn't match defined format,
web page users will see message saying what should be changed. Here
is an example of such message:
To add/edit validation rules, go to Visual Editor page, right-click a field
and select the Properties.
Validate As check box is
available for Text field
format at Edit as tab. Then
you can choose one of validation types from the list.
List of
standard validation types
Number - field value
should be a number.
Time - any valid time
format that match regional settings.
Password - password
field cannot be blank, cannot be 'Password' and should be at least
4 characters long.
Email - field value
should be a valid email address.
Currency - numeric
value. Decimal point is allowed. Examples: 13, 24.95
US Zip Code - five or
ten digit number. Valid formats: 12345, 12345-6789 or 123456789
US Phone Number -
numbers, spaces, hyphens, and parentheses are allowed. Examples:
(123) 456-7890, 123 456 7890, 123 4567
US State - this field
should be two letter US state abbreviation. Examples: AK, AL, CA,
MN.
US SSN - nine digit US
social security number. Valid formats: 123-45-6789 or 123 45
6789
Credit Card - valid
credit card number.
ip_address - valid ip
address (four numbers between 0 and 255 separated by periods).
ip_address is the
validation plugin. More info
about adding your own validation types.
Regular expression -
regular expression (regexp for short) is a special text string for
describing a search pattern. You can get more information about
basic syntax for setting regular expressions at http://www.regular-expressions.info/reference.html.
Examples of regular expressions:
|
·
|
[abc] matches a, b or c |
|
·
|
[a-zA-Z0-9] matches any letter or digit; |
|
·
|
[^a-d] matches any character except a, b, c or d |
|
·
|
regular expression for ip address: |
\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b
matches 1.2.3.4
|
·
|
regular expression for email address: |
^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$ matches
contact@abc.com
To define regular expression, add regular expression to
Regexp field and message
that will be displayed if value entered doesn't match defined
regular expression to Message field. If multilanguage support
is turned on in your project, you will see Multilanguage... button that allows
translating message into several languages. For more information
about multiple language support, see Miscellaneous_settings.
You can test your regular expression by clicking Test button.
How to add
your own validation plugins
To add new validation type, you should create a file with
javascript function that implements data validation and store it at
<PHPRunner install
folder>\source\include\validate folder, where
<PHPRunner install folder> is a folder PHPRunner is installed
to.
You can add any javascript code to your validation plugins. The
javascript function should return nothing if the value was
validated successfully and return error message if the value was
not validated.
Note: The file
name should match the function name.
Example:
As an example, let us create validation plugin that validates ip
address.
Step 1. Create file
ip_address.js.
Step 2. Add the
following javascript function to this file:
|
function ip_address(sVal)
{
var regexp =
/\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/;
if(!sVal.match(regexp))
return 'This field should be a valid IP
address';
else
return true;
}
|
Step 3. Store file
ip_address.js to the <PHPRunner install
folder>\source\include\validate folder. In our case the
folder is C:\Program
Files\PHPRunner6.1\source\include\validate.
Step 4. Start PHPRunner.
Now ip_address validation
type is available in the list of validation types and you can use
it in your projects.
If you want to add a multilanguage message (i.e. error message)
to your validation plugin, you need to create a custom label in
Label editor and use
GetCustomLabel("LABEL1") code
in your javascript function, where LABEL1 is custom label title. Note that
GetCustomLabel function is
applicable only for editing fields like Add/Edit/Register/List with
inline add/edit.
|