I am trying to use the built in verification method for contact form 7 to verify a telephone number.
Contact form 7 markup:
<p>[number* your-telephone min:1000000000 max:9999999999 placeholder "Telephone number"] </p>
<p>[submit "submit"]</p>
So, what I am trying to do here is restrict phone number using the min and max properties of input type of number. But the problem here is that if I enter a telephone number say: 0402356584 then it is less than the min value but is still a phone number.
So, how can I set the min and max value to support all possible 10 digit telephone numbers?
Any other solution different from my approach is also most welcome. Because I have got a feeling that the verification can not be done using min and max attributes.
I also tried to edit the plugin files via functions.php file by using the code from a source but that did not work.
So, if any one has the perfect solution to validate telephone numbers on contact form 7 then please post your answers.
I Think i have nice workaround...
By the default the number field dont have minlength and maxlength validators. You can copy them from wp-content/plugins/contact-form-7/modules/text.php
(in wpcf7_text_form_tag_handler function)... and validation filters
(in wpcf7_text_validation_filter function)
And now paste it to the numbers.php in the right place. So in wpcf7_number_form_tag_handler function atts looks like:
and wpcf7_number_validation_filter function ends with:
phonenumber -> field name
try this one for function.php file.
Filter: https://plugins.trac.wordpress.org/browser/contact-form-7/trunk/modules/text.php
wpcf7_validate_tel
which is using the functionwpcf7_validate_tel( $result, $tag )
Try this:
good luck!!
chucha!
In my case, below code is working. Important point is that input type should be 'tel' as below.
Try this one definitely it will work as per contact form 7 documentation.
You can use [tel* tel-672] field and validate according to your requirement through wpcf7_is_tel filter hook .
Contact form 7 has many pre-defined hooks through which you can validate any field.Here, in the Contact Form 7 formatting.php module, validation rule is defined by following method .You can override it by filter hook mentioned in apply_filters through functions.php
Please add the below mentioned code in functions.php in your activated theme folder and add your validation rule to $result
You can see more