Hello,
Thank you for reaching out!
The Pattern validation option in Checkout Fields for Blocks allows you to define a specific format that user input must follow. This uses regular expressions (RegEx), meaning you need to enter a valid RegEx pattern rather than plain text.
For example, if you want to enforce a format like XX_YY_ZZ (where each section consists of exactly two letters), you could use:
[a-zA-Z]{2}[a-zA-Z]{2}[a-zA-Z]{2}
This pattern ensures:
- Only letters (both uppercase and lowercase) are allowed.
- Each section contains exactly two characters.
- Underscores
_ are required in specific positions.
If users enter a value that doesn’t match the pattern, they will see a validation error message.
Custom Validation (e.g., VAT Number Validation)
Currently, the plugin does not offer built-in support for custom validation functions beyond RegEx patterns. However, if you need VAT number validation, you might consider the following workarounds:
- Use a Pattern Validation for Basic Checks
- Example for an EU VAT Number (starting with two letters, followed by digits):
[A-Z]{2}[0-9]{8,12}
- This ensures the format is correct, but it doesn’t verify whether the VAT number is valid.
- Custom Code via Hooks
- If you need to verify VAT numbers in real-time (e.g., via the VIES API), you can extend WooCommerce checkout validation using custom PHP code.
- You can use the
woocommerce_checkout_process action to add your custom validation logic.
We’ve added this feature request (custom validation for fields, such as VAT number validation) to our internal list of ideas for future updates. If we implement this functionality in an upcoming release, I will make sure to notify you.
Please let me know if you have any further questions!
Best regards,
Thanks for the info. I’ll test it out!
Hello,
You’re most welcome!
How are the tests going? Were you able to achieve the desired validation setup? Please let us know if you need any further assistance—we’re happy to help!
Best regards,
Hello,
I haven’t heard from you in a while, so I’m marking this thread as resolved. Please don’t hesitate to open a new one if you encounter other issues while using our plugin.
Have a fantastic day,