Skip Navigation

[Resolved] Restrict value of number field?

This support ticket is created 4 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 5 replies, has 2 voices.

Last updated by Jennifer 4 years, 3 months ago.

Assisted by: Shane.

Author
Posts
#1779339

Is there a way I can restrict the value of a number field in a form? I only want users to be able to submit values equal to or greater than a particular number, and I want the form to reject the input otherwise, and prompt them to re-enter the value.

#1780209

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jennifer,

Thank you for getting in touch.

You will need to this with some custom javascript.

Can you provide me with a link to the form so that I can write the custom Javascript that is required to do this ?
Thanks,
Shane

#1780299

Hi Shane!

Sure, the form is here: hidden link

I would like to restrict the "Years of Practice" fields (both start year and end year) to only accept values greater than or equal to 1700.

I will also need it to work on my edit form although I can probably just use similar code for both, and could add it myself.

Please let me know if you need more information.

Thank you!

#1780457

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jennifer,

It seems I need to log in to see the form.

I've enabled the private fields so that you can provide me with the login to view the form.

Thanks,
Shane

#1780547

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jennifer,

Here is the jQuery to help resolve this. Add it to the JS section of your form.

jQuery(document).ready(function() {
    jQuery("input[name='wpcf-practice-start-year']").attr({
               // substitute your own
       "min" : 1700          // values (or variables) here
    });
jQuery("input[name='wpcf-practice-end-year']").attr({
               // substitute your own
       "min" : 1700          // values (or variables) here
    });
});



Please let me know if this helps.
Thanks,
Shane

#1780623

That worked perfectly. Thank you!