I was having an issue with link spam in a Gravity Forms paragraph text field. Here is a code snippet that validates the field and prevents link submissions.
Place the code in your theme’s functions.php file. Replace ‘[form number]’ with your form number. Replace ‘[field number] with the field number.
// add custom validation to form
add_filter( 'gform_field_validation_[form number]_[field number]', 'validate_text_1_4', [form number], [field_number] );
function validate_text_1_4( $result, $value, $form, $field ) {
$nourl_pattern = '(http|https)';
if ( preg_match( $nourl_pattern, $value ) ) {
$result['is_valid'] = false;
$result['message'] = 'Message can not contain website addresses.';
}
return $result;
}