Skip Navigation

[Resolved] Phone number field validation required in Toolset

This support ticket is created 3 years, 9 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 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 4 replies, has 2 voices.

Last updated by pramodk-2 3 years, 9 months ago.

Assisted by: Waqar.

Author
Posts
#1902747

Hi Team,

In my requirement, I have a phone number field but there are basic validations missing in Tool set.

Could you please suggest me on how do we achieve the validation of below for the phone number field?

1. Length of the phone number should be '10'.
2. Should allow numbers only (Not characters, special characters etc.,).

Thanks.

#1903483

Hi,

Thank you for contacting us and I'd be happy to assist.

To make sure that only numbers are allowed in the input, you can use the "Number" type custom field, instead of the "Phone".

And to make sure that a user can input exactly 10 numbers in the field in the front-end form, you can include some custom JS in the form, to apply "maxlength" and "minlength" attributes.
( ref: hidden link )

For example, suppose your field's slug is "phone-number", the code would be something like:

jQuery(document).ready(function($){
$("input[name=wpcf-phone-number]").attr("maxlength", "10");
$("input[name=wpcf-phone-number]").attr("minlength", "10");
});

regards,
Waqar

#1904271

Thanks Waqar.

Will test and update you by this Sunday.

Thanks.

#1904759

You're very welcome.

I'll wait to hear back from you.

#1907407

My issue is resolved now. Thank you!