The TextBox Family of Controls
TextBox controls handle basic user input. Different flavors of controls are available for various forms of user input, such as plain text, numbers, or data that requires strict formatting.
The last controls, Email, URL, and Custom, are based on validation and filtering routines introduced in PHP 5.3. The custom field uses PHP's built-in ability to validate against a Perl regular expression to accept only hexadecimal numbers.
Multiple Email Entry and Flexible Separators
The MultipleEmailTextBox control extends the functionality of the standard EmailTextBox by allowing users to enter several email addresses in a single field. Addresses can be separated by a comma, semicolon, any whitespace (spaces, tabs, line breaks), or any combination of these. This gives users a great deal of flexibility and improves usability, especially when inviting or managing several recipients at once.
When data is entered, the control automatically processes the text by splitting it into individual addresses using a regular expression. Each address is trimmed to remove extra spaces and then validated to check if it's a properly formatted email address. Addresses are sorted into two groups: those that are valid and those that are invalid.
- Valid: Contains all recognized and correctly formatted email addresses.
- Invalid: Contains all entries that fail validation and do not match the expected email format.
Developers have easy access to these groups using the getGroupedEmails()
method, which returns two arrays: one for all valid email addresses, and one for invalid ones. This enables custom handling, such as:
- Displaying tailored warning or error messages to users pointing out any addresses that need correction,
- Preventing form submission if invalid entries are present,
- Cleaning or preprocessing the list before saving it to your database or sending invitations.
Usage Example:
// Suppose $textbox is an instance of MultipleEmailTextBox
$result = $textbox->getGroupedEmails();
$valid = $result['valid']; // Array of valid email addresses
$invalid = $result['invalid']; // Array of invalid email addresses
Thanks to MultipleEmailTextBox, accepting multiple e-mails is both user friendly and straightforward for developers to validate and process.
Other TextBox Variants
Alongside MultipleEmailTextBox, you can also use traditional controls for specific data types. For example, URLTextBox ensures only properly formatted web addresses, and CustomTextBox supports additional validation logic through regular expressions. Each variant builds on the base TextBox, but focuses validation and filtering on its respective format.