Table of Contents

## Validation

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.

### Visual Basic Style 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

Examples

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`

###
Javascript Validation Functions

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.

#### Predefined Javascript Functions

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.