# Blocking URL's in paragraph text fields

**URL:** <https://community.gravityforms.com/t/blocking-urls-in-paragraph-text-fields/18800>\
**Category:** Get Help\
**Tags:** gform\_field\_validation\
**Created:** [January 20, 2025, 3:42pm UTC](https://community.gravityforms.com/t/blocking-urls-in-paragraph-text-fields/18800 "2025-01-20T15:42:45Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![user5f07a64341de3865](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/user5f07a64341de3865/32/14308_2.png) [@user5f07a64341de3865](https://community.gravityforms.com/u/user5f07a64341de3865)\
**Post date:** [January 20, 2025, 3:42pm UTC](https://community.gravityforms.com/t/blocking-urls-in-paragraph-text-fields/18800/1 "2025-01-20T15:42:45Z")

</div>

Is the script in the topic below still the preferred method to block url entries in text fields and does it work with the latest version of gravity forms?

> [@How to block URLs in text area](https://community.gravityforms.com/t/how-to-block-urls-in-text-area/11703):
>
> Recently, my websites that use Gravity Forms are receiving manual spam submissions that contain website addresses in the comments field. I’ve tried the following code from a past forum thread, but it isn’t working. Is there any way to block submissions that enter a URL into a text field? // add custom validation to form add\_filter( 'gform\_field\_validation\_74\_7', 'validate\_phone\_74\_7', 10, 4 ); function validate\_phone\_74\_7( $result, $value, $form, $field ) { $nourl\_pattern = '(http|https)';…

---

<div class="post-metadata">

**Author:** ![toothless](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/toothless/32/15995_2.png) [@toothless](https://community.gravityforms.com/u/toothless)\
**Post date:** [January 21, 2025, 7:23am UTC](https://community.gravityforms.com/t/blocking-urls-in-paragraph-text-fields/18800/2 "2025-01-21T07:23:27Z")

</div>

Hi Shaun,

Yes, the provided code is still effective in blocking website URLs from the paragraph field.

 ![Error message@2x](https://us1.discourse-cdn.com/flex020/uploads/gravityforms1/original/3X/f/5/f5dd2d4c1b1797d0ee81d9752aad8b6793d1750b.jpeg)

```php
add_filter( 'gform_field_validation_1_74', 'validate_input_1_74', 10, 4 );

function validate_input_1_74( $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;
}

```

Have you had a chance to test it?

---

<div class="post-metadata">

**Author:** ![user5f07a64341de3865](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/user5f07a64341de3865/32/14308_2.png) [@user5f07a64341de3865](https://community.gravityforms.com/u/user5f07a64341de3865)\
**Post date:** [January 27, 2025, 3:25pm UTC](https://community.gravityforms.com/t/blocking-urls-in-paragraph-text-fields/18800/3 "2025-01-27T15:25:46Z")

</div>

I was able to test it and confirm that it’s working in my test environment, thanks.

Is there a benefit (other than an error message appearing) vs. using conditional logic to hide the submit button if my message field contains “http” or “https”. That’s what I was doing as a quicker work around.

---

<div class="post-metadata">

**Author:** ![toothless](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/toothless/32/15995_2.png) [@toothless](https://community.gravityforms.com/u/toothless)\
**Post date:** [January 28, 2025, 5:54am UTC](https://community.gravityforms.com/t/blocking-urls-in-paragraph-text-fields/18800/4 "2025-01-28T05:54:30Z")

</div>

Hi Shaun,

We can use jQuery code to hide the submit button if the paragraph field contains any URL. However, it might not work smoothly, so you may see the button while typing.

I recommend using the first option, but if you prefer, you can use the following code as well. It only performs front-end validation, not server-side validation.

```js
jQuery(document).ready(function($) {
    // Function to check the text and update button visibility
    function updateButtonVisibility() {
        var messageText = $('#input_1_74').val() || '';
        
        if (messageText.toLowerCase().includes('http') || messageText.toLowerCase().includes('https')) {
            $('#gform_submit_button_1').css('display', 'none');
        } else {
            $('#gform_submit_button_1').css('display', 'block');
        }
    }

    $(document).on('change keyup paste', '#input_1_74', updateButtonVisibility);
    
    if ($('#input_1_74').length) {
        updateButtonVisibility();
    }
});

```

Give it a try, and let me know how that goes!

---

<div class="post-metadata">

**Author:** ![user5f07a64341de3865](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/user5f07a64341de3865/32/14308_2.png) [@user5f07a64341de3865](https://community.gravityforms.com/u/user5f07a64341de3865)\
**Post date:** [January 28, 2025, 3:20pm UTC](https://community.gravityforms.com/t/blocking-urls-in-paragraph-text-fields/18800/5 "2025-01-28T15:20:27Z")

</div>

This works, thanks for the suggestion.

It’s a shame that Gravity forms doesn’t have built in toggle to prevent URL’s in fields as it seems like a common type of spam for contact forms.

---

<div class="post-metadata">

**Author:** ![richardw8k](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/richardw8k/32/2354_2.png) [@richardw8k](https://community.gravityforms.com/u/richardw8k)\
**Post date:** [January 28, 2025, 4:08pm UTC](https://community.gravityforms.com/t/blocking-urls-in-paragraph-text-fields/18800/6 "2025-01-28T16:08:15Z")

</div>

You can suggest this feature directly to the product management team for consideration when planning future releases on the [Gravity Forms](https://roadmap.forms.gravity.com/tabs/1-under-consideration/submit-idea) product roadmap page.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/gravityforms1/original/2X/f/fef63f0599c45e0218c30d9f5d7ca8bff9b00189.png) [@system](https://community.gravityforms.com/u/system)\
**Post date:** [February 27, 2025, 4:09pm UTC](https://community.gravityforms.com/t/blocking-urls-in-paragraph-text-fields/18800/7 "2025-02-27T16:09:12Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
