The default validation function for tel number only accept number and – and +. To add ( and ) to it, add this code to your theme’s functions.php:
add_filter( 'wpcf7_is_tel', 'your_custom_wpcf7_is_tel', 10, 2 );
function your_custom_wpcf7_is_tel( $result, $tel ) {
$result = preg_match( '/^[0-9()+-]*$/', $tel );
return $result;
}
Thank you!
I ran a browser test and noticed the placeholder text is not showing in IE7 and IE8 on our sites. It shows for all other browser tests.
http://clientdemo.5ivefold.com/v2
For the tel field, what if the user adds spaces?
Examples: 877 464 5693 or (877) 464-5693
Also I noticed the validation errors are not showing correctly.
When a user enters invalid email or tel it shows the same message instead of the related field message.
Validation errors occurred. Please confirm the fields and submit it again.
For the tel field, what if the user adds spaces?
Examples: 877 464 5693 or (877) 464-5693
Well, they could also use a literal period.
123.456.7890
So you’ll need to add spaces and a literal period like so:
add_filter( 'wpcf7_is_tel', 'your_custom_wpcf7_is_tel', 10, 2 );
function your_custom_wpcf7_is_tel( $result, $tel ) {
$result = preg_match( '/^[\d\s()+-.]*$/', $tel );
return $result;
}
Note, that I replaced [0-9] with \d because it’s a bit faster.
You might want to put a min/max in there when you place the code in your form. Like 10/20
[tel your-tel 10/20 "123-456-7890"]
The minus sign should be placed at the last like [\d\s().+-] because it also works as a range separator.
http://php.net/manual/en/regexp.reference.character-classes.php
Yes, that was my mistake. It can also be placed at the beginning as well.
Were you able to test the Internet Explorer 8 browser issue?
I ran a browser test and noticed the placeholder/watermark text is not showing in IE7 and IE8. It shows for all other browser tests.
5ivefold, you should open a new thread if you start a new topic.
Thanks – this is a big help for me because many of the artists who use my form like to use periods instead of dashes in the phone number. The min/max thing doesn’t work though. Adding 10/20 to my field only shortens the appearance of the field. I can submit a one-digit “phone number”.