Skip Navigation

[Resolved] Number field exact digits (and only numbers)

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.

This topic contains 3 replies, has 2 voices.

Last updated by Miguel 2 years ago.

Author
Posts
#2541975

Tell us what you are trying to do?
I have a number field that should be entered exactly 11 digits no less no more. They must also be numbers only (no symbols).

Is there any documentation that you are following?
https://toolset.com/forums/topic/limiting-field-length-to-display/
but not exactly

Is there a similar example that we can see?

What is the link to your site?
it's a local site

#2543703

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

It is considered a custom development and most probably you need to use some sort of Javascript code to achieve that.

https://toolset.com/course-lesson/adding-custom-javascript-to-views-templates-and-archives/

You can check this sample to get started:

https://stackoverflow.com/questions/13491589/javascript-regex-to-match-only-up-to-11-digits-one-comma-and-2-digits-after-it

Also, you will need to do a check later in PHP using the Validate Hook in Toolset forms so if for some reason JS fails on the browser of the customer, backend would not allow the problematic entry:

https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate

Thanks.

#2544921

I'm not going to implement this.
THank you anyway

#2547399

Finally I added the following js to that form:

jQuery(document).ready(function ($) {
  $('[name^=wpcf-cuit]').attr('minlength',11);
  $('[name^=wpcf-cuit]').attr('maxlength',11);
});