Home Forums General Issues Validate text area


Validate text area

  • Hi! I’d like to validate my text areas so they don’t get submitted if they are empty (currently doing that by marking them as required), but I also need to validate that the user inputs at least 10 words or something like that.

    How could I achieve this?

  • You need to add a filter to validate the value of your field. The documentation is here

    Something like this:

    add_filter('acf/validate_value/name=your_field_name', 'my_validate_function', 10, 4);
    function my_validate_function($valid, $value, $field, $input) {
        $words = explode(' ', $value);
        if (count($words) < 10) {
            $valid = 'Please enter at least 10 words!';
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Validate text area’ is closed to new replies.