WooCommerce Field Validation – Regex, Length & Word Limits

Introduction

Advanced Validation makes sure customers enter correctly formatted data in your Text and Textarea fields — phone numbers, codes, messages of a certain length, and more.
Validation runs live as the customer types, and the Add to Cart button stays disabled until the input is valid.

This guide is customer-focused and explains each setting in simple language, with practical examples.


What Is Advanced Validation?

Advanced Validation is a set of rules you can add to Text and Textarea fields in Extra Product Options for WooCommerce. It checks the customer’s input both in the browser (instant feedback) and on the server (security).

Common use cases:

  • phone numbers with an exact number of digits
  • email or reference codes in a specific format
  • gift messages with a minimum/maximum length or word count

Where to Configure Validation

Go to: WP Admin -> WooCommerce -> Extra Product Options -> Addons Builder

Edit a Text or Textarea field, open the Options Settings tab, and enable Advanced Validation Rules.


Quick Setup (Step by Step)

  1. Edit a Text or Textarea field.
  2. Open the Options Settings tab.
  3. Turn on Advanced Validation Rules.
  4. Configure any combination of Regex, Min/Max Length, Min/Max Words, and a custom Error Message.
  5. Save addon and test on frontend.

Validation Options Explained

Regex Pattern

A regular expression the value must match. Examples:

  • ^[0-9]{10}$ → exactly 10 digits (phone)
  • ^[a-z0-9.-]+@[a-z0-9.-]+\.[a-z]{2,}$ → email format

Min Length / Max Length

Minimum and maximum number of characters allowed.

Min Words / Max Words

Minimum and maximum number of words allowed (useful for gift messages).

Custom Error Message

The message shown when validation fails. Leave it empty to use a sensible default.


Validation Behavior

  • Validation runs on blur (leaving the field) and on input (as the customer types).
  • An error message stays visible until the requirements are met.
  • Add to Cart is disabled while any visible field is invalid, and re-enabled once all fields pass.
  • Validation is re-checked on the server at add-to-cart for security.

Real Examples

Example 1: 10-digit phone

Regex ^[0-9]{10}$, Error Message “Enter exactly 10 digits.” → only 10-digit numbers are accepted.

Example 2: Gift message limits

Min Words = 3, Max Words = 30 on a Textarea → the message must be between 3 and 30 words.


How its Work


Best Practices

  • Write a clear custom error message so customers know exactly what to fix.
  • Use Min/Max Words for messages and Regex for strict formats.
  • Test your regex with real input before going live.

Troubleshooting

Add to Cart stays disabled

  • A visible field is still invalid — read the inline error and correct the input.

Valid input is being rejected

  • Re-check the Regex pattern and the Min/Max Length and Words values.

Conclusion

Advanced Validation keeps your order data clean and prevents invalid submissions, with instant feedback for customers and server-side enforcement for security.


Frequently Asked Questions

Find answers to commonly asked questions about Advanced Validation.

Still have a question?

If you have any other queries, feel free to reach out to us. Our knowledgeable team is here to help!