I wanted to validate a text field in Gravity Forms: The text field must end with Ltd. (for example "Company XYZ Ltd."). Can somebody please point out the error?
add_filter( 'gform_field_validation_23_7', 10, 4 );
function custom_validation_ends_with_Ltd( $result, $value, $form, $field ) {
if (! preg_match('/Ltd.$/', $value)) {
$result['is_valid'] = false;
$result['message'] = 'The company name must end with Ltd. .';
}
return $result;
}