Quantcast
Channel: WordPress.org Forums » [Contact Form 7] Support
Viewing all articles
Browse latest Browse all 49500

MickeyRoush on "[Plugin: Contact Form 7] Tel number field error"

$
0
0

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"]


Viewing all articles
Browse latest Browse all 49500

Trending Articles