# Filter/restrict specific characters or strings in fields

**URL:** <https://community.gravityforms.com/t/filter-restrict-specific-characters-or-strings-in-fields/11605>\
**Category:** Get Help\
**Tags:** gform\_field\_validation, regex\
**Created:** [January 14, 2022, 1:12pm UTC](https://community.gravityforms.com/t/filter-restrict-specific-characters-or-strings-in-fields/11605 "2022-01-14T13:12:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andre\_B](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@Andre\_B](https://community.gravityforms.com/u/Andre_B)\
**Post date:** [January 14, 2022, 1:12pm UTC](https://community.gravityforms.com/t/filter-restrict-specific-characters-or-strings-in-fields/11605/1 "2022-01-14T13:12:23Z")

</div>

Is there any way to filter/restrict/block specific characters or strings in fields?

Example: the text paragraph field  
When somebody uses “http://” in it, the field displays an error message and the form can’t be sent

Other possible characters to block could be “:” or “/” .

I know it’s stupid since clickable links will also be created when the user just submits “[mydomain.com](http://mydomain.com)”, but I’m doing this for a client who’s a little resistant to these kind of arguments.

---

<div class="post-metadata">

**Author:** ![uamv](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/uamv/32/1412_2.png) [@uamv](https://community.gravityforms.com/u/uamv)\
**Post date:** [January 17, 2022, 7:15pm UTC](https://community.gravityforms.com/t/filter-restrict-specific-characters-or-strings-in-fields/11605/2 "2022-01-17T19:15:50Z")

</div>

Give a look at the filter [gform\_field\_validation](https://docs.gravityforms.com/gform_field_validation/) and the examples outlined there. It’ll let you put such restrictions in place.

---

<div class="post-metadata">

**Author:** ![Andre\_B](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@Andre\_B](https://community.gravityforms.com/u/Andre_B)\
**Post date:** [January 18, 2022, 12:10pm UTC](https://community.gravityforms.com/t/filter-restrict-specific-characters-or-strings-in-fields/11605/3 "2022-01-18T12:10:40Z")

</div>

Many thanks.

---

<div class="post-metadata">

**Author:** ![Andre\_B](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@Andre\_B](https://community.gravityforms.com/u/Andre_B)\
**Post date:** [January 19, 2022, 4:33pm UTC](https://community.gravityforms.com/t/filter-restrict-specific-characters-or-strings-in-fields/11605/4 "2022-01-19T16:33:51Z")

</div>

Sorry I have to ask again.  
This code sample comes from gform\_field\_validation. It’s to filter out certain words.  
While it does work great for the specific words (in this example ‘one’ and ‘two’), it doesn’t work with strings WITHIN words, like www or http. How can I add a wildcard placeholder to the string to make this work for any “word” starting with ‘http’?  
‘http\*’ doesn’t work, I’ve tried already.

```auto
add_filter( 'gform_field_validation', function ( $result, $value, $form, $field ) {
    GFCommon::log_debug( __METHOD__. '(): Running...' );
    // Only for Single Line Text and Paragraph fields.
    if ( $field->type == 'text' || $field->type == 'textarea' ) {
 
        if ( $result['is_valid'] ) {
            $stop_words = array( // List of words to not allow in lowercase.
                'one',
                'two',
            );
 
            if ( in_array( strtolower( $value ), $stop_words ) ) {
                GFCommon::log_debug( __METHOD__. '(): Stop word detected: ' . $value );
                $result['is_valid'] = false;
                $result['message'] = 'Sorry, you used a not allowed word.';
            }
        }
 
    }
 
    return $result;
}, 10, 4 );

```

---

<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 18, 2022, 4:34pm UTC](https://community.gravityforms.com/t/filter-restrict-specific-characters-or-strings-in-fields/11605/5 "2022-02-18T16:34:15Z")

</div>

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