Blocking urls in name field

I can get the below to work to block urls in text or paragraph fields, but now spammers are putting the url in the name field. How do I add the name field to the below? If I add
|| $field->type == 'name' to the if statement, the form comes back with a message there is a website error upon submission. But the below does not block an url from being submitted in the name field.

//Prevent submission if a URL is entered into Text or Paragraph fields
add_filter( 'gform_field_validation', function ( $result, $value, $form, $field ) {
    // Only for Single Line Text or Paragraph fields.
    if ( $field->type == 'text' || $field->type == 'textarea' || $field->type == 'name' ) {
 
        $has_url = false;
 
        // The following regex is just an example, feel free to change it.
        if ( preg_match ( '/www\.|http:|https:\/\/[a-z0-9_]+([\-\.]{1}[a-z_0-9]+)*\.[_a-z]{2,5}'.'((:[0-9]{1,5})?\/.*)?$/i', $value ) ) {
            $has_url = true;
        }
 
        if ( true === $has_url ) {
            $result['is_valid'] = false;
            $result['message']  = empty( $field->errorMessage ) ? 'Sorry, URL not allowed!' : $field->errorMessage;
        }
    }
 
    return $result;
}, 10, 4 );

Hi there,

You can follow my solution provided on another ticket below.

or

You can also suggest this feature directly to the product management team for consideration when planning future releases on the Gravity Forms product roadmap page.

If I use the code (below changed for my form 6, field 1 which is the name field) I get “WordPress Error: There has been a critical error on this website.” upon form submission, regardless if there is an url in the name field or not. I have tested this on various sites to make sure it wasn’t a plugin conflict.

add_filter( 'gform_field_validation_6_1', 'validate_input_6_1', 10, 4 );
function validate_input_6_1( $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;
}

The only way I can see around this it so not use the name field for first and last name, but make two text fields, one for first name and one for last name. I had problems with the name field using Gravity Wiz on one of my projects and had to do this.

The name field is a multi-input field type, so $value is an array, which preg_match doesn’t support. You’ll need to convert the value to a string before you can check what it contains, e.g.

$nourl_pattern = '(http|https)';
$value = is_array( $value ) ? implode ( ' ', $value ) : $value;
if ( preg_match( $nourl_pattern, $value ) ) {