15 Regex Validation
Regex (or regular expression) is a way to check if the user's input is correct. Regex is a language, and you can use PHP Regex with our plugin (PCRE, click here for more details).
For example if you would like to check that the user can type only letters:
- Click on "PHP Regex"
- Click on "New Regex (PHP)"
- Add a "Name *" for your regex, for example "Only letters" and write a Regex in the "Regex (PHP)" field, for example: "/^[a-zA-Z]$/" and click on "Save"
- Go to the field which you want to use the regex rule, it must be a "Text" field
- You can write the regex rule directly in the "Validation Regex Rule" field or load it from the library by clicking on the cloud icon.
- Write an error message that you want to show if the regex rule conditions are not met in the "Regex Error Message" field.
If you try to put a number in your website product, you'll get an error message. If you try to put letters, no errors are show and you can add the product to cart.