How to set a minimum number of characters?

I have a zip code field that we want a user to type in exactly 5 digits (USA postal code). Is there a way we can do this with Gravity forms?

I found this, but it breaks the form. I put this both in my parent and child theme functions.php file Require Minimum/Maximum Character Limit for Gravity Forms - Gravity Wiz

We have an elite license if that helps. Thanks

Hi Carlos. Using that code should not break your form. Can you show or explain exactly what code you added to your child theme functions.php file?

1 Like
new GW_Minimum_Characters( array( 
'form_id' => 524,
'field_id' => 1,
'min_chars' => 5,
'max_chars' => 6,
'min_validation_message' => 5 ( 'Oops! You need to enter at least 7 characters.' ),
'max_validation_message' => 6 ( 'Oops! You can only enter 12 characters.' )
) );

When it it comes time to ask the question being validated, it just spins. Never goes to next question.

Here is a video showing what happens to the form after using the code snippet β†’ Recording #3 - YouTube

I also use DIVI theme builder. Not sure if that complicates this. Placed in both parent and child theme functions.php files.

Hi Carlos. First, you should install the code in only one place. The child theme functions.php is probably best, so it is not overwritten by an update to the parent. If the child theme is going to be updated as well, you will lose that code then. You can also use a plugin like this one to add code snippets to your site:

But, there is more code to add than what you shared here. That is the instantiation code. That enables you to configure the snippet for usage, or multiple uses. You also need this code:

https://gist.githubusercontent.com/spivurno/8220561/raw/9b8c6f6702769b2bc8bf8135bae3db2b781bb6b0/gw-gravity-forms-minimum-characters.php

Do you have that code installed as well? You will need both.

Gravity Wiz also has a helpful document about snippet troubleshooting here:

1 Like