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.
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
Thanks Waqar.
Will test and update you by this Sunday.
Thanks.
You're very welcome.
I'll wait to hear back from you.
My issue is resolved now. Thank you!