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;
}