# Validation rules

### Introduction

Ensuring accurate and complete data collection is critical to maintaining a high-quality database and improving user experience. In The Wallet Crew, the registration form supports a powerful field-level validation system to help administrators enforce data standards. This article outlines how form data is validated and the default rules available.

Understanding these rules will help both technical and business users configure forms that capture the right information in the right format, minimizing errors and improving data usability across the platform.

### Core Explanation

Field validation in The Wallet Crew occurs at the individual field level. Each field can be configured with specific rules to ensure the data entered is accurate and meets business requirements.

Here are the available validation rules:

#### Required

* Indicates whether the field must be filled out.
* For checkboxes and switchboxes, this means the box must be checked.

#### `minLength`

* Defines the **minimum number of characters** required for a field's value.
* Useful for fields like names or identification numbers.

#### `maxLength`

* Sets the **maximum number of characters** allowed in the field.
* Helps prevent excessively long inputs that could disrupt layout or storage.

#### `email`

* Combines two layers of validation:
  1. **Regular Expression Check**: Uses the following default regex to validate format:

     ```js
     /^[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$/
     ```

     This regex can be **overridden** with a custom one if needed.
  2. **Domain Check via DNS**: The Wallet Crew verifies that the email domain accepts mail by checking for **MX records**.

#### `phone`

* Validates phone numbers using the [react-phone-number-input](https://catamphetamine.gitlab.io/react-phone-number-input/) component.
* This is based on Google’s international phone number validation library.
* Ensures numbers are correctly formatted and country codes are recognized.

#### `expression`

* Allows administrators to define a **custom regular expression** to validate the field.
* Flexible option for enforcing format-specific data (e.g., postal codes, IDs).

#### `equality`

* Compares the field’s value to:
  * Another field’s value (e.g., "Confirm Password")
  * A static constant value
* Ensures consistency and matching where required.

### Tips & Best Practices

* **Use `required` sparingly**: Making too many fields mandatory can negatively impact user experience.
* **Validate early**: Implement client-side validation for faster feedback, and always reinforce with server-side checks.
* **Customize regex cautiously**: Only override the default email regex if you fully understand the implications.
* **Use `equality` for sensitive fields**: Perfect for validating repeated entries like passwords or emails.

### Conclusion

The Wallet Crew form validation system offers a flexible and powerful way to ensure data quality. By leveraging default validation rules, administrators can create robust forms that help maintain clean, reliable datasets while enhancing user experience. For advanced needs, custom expressions and rule overrides provide even more control.
