When you save a record, phpLens will automatically validate all fields based on the following criteiria. If the field has been defined as must fill field (using the mustFill property), the user is warned. If you require more detailed validation, we provide two ways of validating your data: Visual Basic style input mask, or Javascript validation.
| X | 0-9 and A-Z, must exist |
| x | 0-9 and A-Z. This character is optional. |
| # | 0-9, must exist. |
| 9 | 0-9. This character is optional |
| + | Positive numbers only |
| & | Any character, must exist |
| ? | Any character, optional |
| \\\\ | escape character |
| > | Uppercase |
| < | Lowercase |
| Telephone numbers with no area code. 7 digits must be filled, but some newer phone numbers have 8 digits, so make 1 character optional. | 9###-#### |
| Car part number with the format: 3 digit number, a hyphen followed by a 3 or 4 letter code | ###-XXXx |
The first character must be the equals (=) character. All subsequent characters are treated as standard Javascript regular expression characters. /expr/ delimiters are not required. For PHP programmers, Javascript regular expression syntax follows preg_match. Some examples follow:
| Value must be either CAR or BOOK, case-insensitive. The $ at the end indicates that no further characters will be accepted. | ([Cc][Aa][Rr])|([Bb][Oo][Oo][Kk])$ |
| Value must begin with 'A' or 'a' followed by any other characters | [aA].* |
Remember that the regular expressions are case-sensitive.
The second optional parameter is the error message on error.
The first character must be the equals (=) character.
| Description | Code |
| To validate email of the form: user@domain.com | =EMAIL |
| Credit cards (not available yet) | =CREDITCARD |
To validate email a regular expression is used. This regular expression
is defined as a constant called PHPLENS_EMAIL_REGEX. You can override
it by defining this constant before phplens.inc.php is included in your main
php file.
The regular expression used is ugly but powerful: ^(\\\\S+@).+((\\\\.com)|(\\\\.edu)|(\\\\.gov)|(\\\\.int)|(\\\\.mil)|(\\\\.net)|(\\\\.org)|(\\\\.info)|(\\\\.biz)|(\\\\.name)|(\\\\.pro)|(\\\\.museum)|(\\\\.coop)|(\\\\.aero)|(\\\\.[a-z]{2,2}))$
This regular expression is defined as a constant in the phplens.inc.php file,
and can be modified to suit your needs.
You can also call javascript functions in phpLens 4.2 or later to validate your code. Assume you want to validate the field CM_ID based on the following rules:
$lens->validation = 'CM_ID^%validatefn(#)';
Assume that the applet id is CMAPPLET, so the form name will be phplens_CMAPPLET_edit. To find out the field names, you will have to check the HTML output generated by phpLens. The general rule is the field name is prefixed by lens_F{$type}_, where {type} is the internal phpLens/ADOdb data type. Here is the sample javascript code:
function validatefn(val)
{
if (val.length == 0) return true; // criteria (1)
if (val <= 0) return false; // criteria (2)
var myform = document.phplens_CMAPPLET_edit
if (!myform.lens_FC_CM_NAME.value) { // criteria (3)
alert('The name field must be filled');
return '';
}
return true;
}
The javascript function should return: