PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Minimum Word Count Custom Validation

  1. Hello,

    I had a need to perform custom validation on a field so that at least 150 words were filled in. I noticed on the support forums that no code example existed. Since I figured this out, I thought I would share my code. I added this to my functions.php file using the WordPress theme editor. Change the name of the filter to suit your situation.

    Filter name: gform_field_validation_11_70
    11 refers to my form id
    70 refers to the field id on my form

    Kind regards,
    Casey

    // Added custom validation for minimum word count
    add_filter("gform_field_validation_11_70", "validate_word_count", 10, 4);
    
    function validate_word_count($result, $value, $form, $field){
        if (str_word_count($value) < 150) //Minimum number of words
        {
            $result["is_valid"] = false;
            $result["message"] = "Please enter at least 150 words.";
        }
        return $result;
    }
    Posted 11 years ago on Monday October 15, 2012 | Permalink
  2. Thank you for posting that solution.

    Posted 11 years ago on Tuesday October 16, 2012 | Permalink
  3. This was discussed recently here:
    http://www.gravityhelp.com/forums/topic/minimum-number-of-characterswords

    Posted 11 years ago on Tuesday October 16, 2012 | Permalink

This topic has been resolved and has been closed to new replies.