regex_field_validator
# Regex Field Validator
**Project Summary (200 characters max):**
Adds customizable regular expression validation to text fields with backend configuration. Perfect for enforcing data formats like phone numbers, emails, or custom patterns.
---
## Introduction
The Regex Field Validator module provides a simple yet powerful solution for validating text field input using regular expressions. If you're new to Drupal, this module helps you ensure that users enter data in the exact format you need - whether that's phone numbers, email addresses, product codes, or any custom pattern you define.
Instead of accepting any text input, this module lets you define rules (called regular expressions) that the text must follow. For example, you can ensure phone numbers are entered as (555) 123-4567 or that product codes follow a specific ABC-123 format. The best part? You can configure these rules directly from Drupal's admin interface without writing any code.
**Basic Functionality:**
- Adds regex validation to any text field (single-line or multi-line)
- Backend configuration interface for setting validation rules
- Custom error messages for failed validation
- Works with existing content types and fields
**Unique Features:**
- **No coding required**: Configure validation patterns through Drupal's admin interface
- **Field-specific validation**: Different fields can have different validation rules
- **Flexible patterns**: Support for any valid regular expression
- **User-friendly error messages**: Customize what users see when validation fails
- **Enable/disable per field**: Turn validation on or off for individual fields
**When to Use This Module:**
- Enforcing specific formats for phone numbers, postal codes, or ID numbers
- Validating email addresses with custom domain requirements
- Ensuring product codes or SKUs follow company standards
- Restricting input to alphanumeric characters only
- Creating custom validation for specialized data entry forms
**Common Use Cases:**
- **E-commerce sites**: Product codes, SKUs, serial numbers
- **Contact forms**: Phone numbers, postal codes, reference numbers
- **User registration**: Username formats, ID numbers
- **Content management**: Article codes, taxonomy term formats
- **Data collection**: Survey responses, form submissions with specific formats
Post-Installation
After installing the module, here's how to set it up:
1. **Navigate to your content type**: Go to Structure → Content Types → [Your Content Type] → Manage Form Display
2. **Choose the field**: Find the text field you want to validate
3. **Change the widget**: Select either "Text field with regex validation" or "Textarea with regex validation"
4. **Configure validation**: Click the settings gear icon and:
- Check "Enable regex validation"
- Enter your regular expression pattern (without delimiters)
- Customize the error message (optional)
- Save your settings
**No additional configuration pages** are needed - everything is configured at the field level. The module integrates seamlessly with Drupal's existing field management system.
**Special Considerations:**
- Test your regex patterns thoroughly before deploying to production
- Provide clear error messages to help users understand the required format
- Consider providing format examples in field descriptions
- The module validates on form submission (server-side validation)
Additional Requirements
This module requires only Drupal core modules:
- **Field module** (core) - for field management
- **Text module** (core) - for text field support
- **PHP PCRE support** - standard in most PHP installations
**No external libraries, APIs, or additional modules are required.**
Recommended modules/libraries
While not required, these modules can enhance your validation setup:
- **[Field Validation](https://www.drupal.org/project/field_validation)** - For additional validation types beyond regex
- **[Clientside Validation](https://www.drupal.org/project/clientside_validation)** - Adds client-side validation for better user experience
- **[Field Group](https://www.drupal.org/project/field_group)** - For organizing fields with validation into logical groups
- **[Field Permissions](https://www.drupal.org/project/field_permissions)** - For controlling who can edit validated fields
Similar projects
**[Field Validation](https://www.drupal.org/project/field_validation)**
- Offers many validation types including regex
- More complex configuration
- **Difference**: Regex Field Validator focuses specifically on regex validation with simpler, field-widget-based configuration
**[Webform Validation](https://www.drupal.org/project/webform_validation)**
- Provides validation for webforms specifically
- **Difference**: Our module works with standard Drupal content fields, not webforms
**What makes Regex Field Validator unique:**
- **Simplicity**: Configuration happens directly in the field widget settings
- **Focus**: Specifically designed for regex validation
- **Flexibility**: Works with any text field type
- **User-friendly**: No complex rule building - just enter your regex pattern
For commercial support or custom development, please contact the module maintainers through their Drupal.org profiles.
Community Documentation
**Getting Started:**
- [Module installation guide](https://www.drupal.org/docs/extending-drupal/installing-modules)
- [Field management basics](https://www.drupal.org/docs/user_guide/en/structure-fields.html)
**Regular Expression Resources:**
- [RegEx101](https://regex101.com/) - Test and debug your patterns
- [Regular Expressions Guide](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Ex...)
- [Common regex patterns](https://regexlib.com/)
---
## Additional Information
**Security Note:** This module performs server-side validation only. For enhanced security and user experience, consider combining with client-side validation modules.
**Performance:** The module has minimal performance impact as validation only occurs during form submission.
**Multilingual Support:** Error messages support Drupal's translation system for multilingual sites.
**Upgrade Path:** The module is designed to be upgrade-safe with proper configuration storage in Drupal's field settings.