# Help on picking the correct field to work with \[RESOLVED\]

**URL:** <https://community.gravityforms.com/t/help-on-picking-the-correct-field-to-work-with-resolved/10557>\
**Category:** Get Help\
**Tags:** gform\_field\_validation, function-call, urls, spam\
**Created:** [August 12, 2021, 11:01pm UTC](https://community.gravityforms.com/t/help-on-picking-the-correct-field-to-work-with-resolved/10557 "2021-08-12T23:01:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Netz](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/netz/32/3426_2.png) [@Netz](https://community.gravityforms.com/u/Netz)\
**Post date:** [August 12, 2021, 11:01pm UTC](https://community.gravityforms.com/t/help-on-picking-the-correct-field-to-work-with-resolved/10557/1 "2021-08-12T23:01:15Z")

</div>

Hi All,

I wanted to implement a function that avoid urls in text fields. (Spammers)  
I found a nice topic [here](https://community.gravityforms.com/t/how-to-block-links-in-text-field-resolved/5865):  
But when I add this to my functions.php I dont get any results.

How do I change this to nice little code snippet to suit my form.  
Can someone guide a novice coder like me… Please

How do I find my field ID so the code will work  
(The code snippet from link… says Phone\_validate …? Should be URL check - Not??)

I would like both… 😆  
Phone check not longer than 10 numbers and not starting with other than +45  
Trying to avoid all other countries than “home” (Denmark)

But main idea is to stop spammers adding urls: http|https|www

In advance

Thx  
Netz

---

<div class="post-metadata">

**Author:** ![sacom](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/sacom/32/53_2.png) [@sacom](https://community.gravityforms.com/u/sacom)\
**Post date:** [August 13, 2021, 3:06pm UTC](https://community.gravityforms.com/t/help-on-picking-the-correct-field-to-work-with-resolved/10557/2 "2021-08-13T15:06:13Z")

</div>

HI Netz,

This snippet will prevent people from adding URLs to Single Line Text and Paragraph fields, no need to put any field id’s or edit anything, just copy/paste to your site:

```auto
add_filter( 'gform_field_validation', function ( $result, $value, $form, $field ) {
	// Only for Single Line Text and Paragraph fields.
	if ( $field->type == 'text' || $field->type == 'textarea' ) {

		$has_url = false;

		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 ( $has_url ) {
			$result['is_valid'] = false;
			$result['message'] = empty( $field->errorMessage ) ? 'Sorry, URL not allowed!' : $field->errorMessage;
		}

	}

	return $result;
}, 10, 4 );

```

And this one will add a new “Custom” phone format to the Phone filed settings, you need to select it and save the field settings. Then the field will require the user a 10 digits phone, prefix will be already added:

```auto
add_filter( 'gform_phone_formats', 'gf_custom_phone_format' );
function gf_custom_phone_format( $phone_formats ) {
    $phone_formats['custom'] = array(
        'label' => 'Custom',
        'mask' => '+459999999999',
        'regex' => '/^\+45[0-9]{10}$/',
        'instruction' => '',
    );
 
    return $phone_formats;
}

```

---

<div class="post-metadata">

**Author:** ![Netz](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/netz/32/3426_2.png) [@Netz](https://community.gravityforms.com/u/Netz)\
**Post date:** [August 17, 2021, 2:20pm UTC](https://community.gravityforms.com/t/help-on-picking-the-correct-field-to-work-with-resolved/10557/3 "2021-08-17T14:20:45Z")

</div>

@sacom  
Wow… You are a true hero. Thanks a million! And you are fast.  
Thumps up and a million thanks for this perfect help!  
You are a keeper 😆

---

<div class="post-metadata">

**Author:** ![chrishajer](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/chrishajer/32/88_2.png) [@chrishajer](https://community.gravityforms.com/u/chrishajer)\
**Post date:** [August 17, 2021, 2:22pm UTC](https://community.gravityforms.com/t/help-on-picking-the-correct-field-to-work-with-resolved/10557/4 "2021-08-17T14:22:56Z")

</div>


