How to require whole numbers in Gravity Forms' Number field

The Number Field in Gravity Forms allows users to enter decimals. If you want to force the number to be an integer (whole numbers, including negative numbers), you can add this code below.

This code will work with Gravity Forms' Range Min and Max settings; if you want to only allow year values, you can set the Min to 1900, for example. For age values, you could set the Min to 0 and the max to 130.

Note: For this code to work, make sure the Output HTML5 setting is enabled in Gravity Forms Settings.

If you want this to modify only one form or only a single field for a form, modify the name of the filter as described in the Usage section of the Gravity Forms docs site.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.