wpcf7_is_tel() │ CF7 1.0

Checks whether the given text is a well-formed telephone number.

Хуки из функции

Возвращает

null. Ничего (null).

Использование

wpcf7_is_tel( $text );
$text(обязательный)
.

Код wpcf7_is_tel() CF7 6.2.4.1

function wpcf7_is_tel( $text ) {
	$text = preg_replace( '/[#*].*$/', '', $text ); // Remove extension
	$text = preg_replace( '%[()/.*#\s-]+%', '', $text );

	$is_international = (
		str_starts_with( $text, '+' ) ||
		str_starts_with( $text, '00' )
	);

	if ( $is_international ) {
		$text = '+' . preg_replace( '/^[+0]+/', '', $text );
	}

	$result = true;

	if ( ! preg_match( '/^[+]?[0-9]+$/', $text ) ) {
		$result = false;
	}

	if ( ! ( 5 < strlen( $text ) and strlen( $text ) < 16 ) ) {
		$result = false;
	}

	return apply_filters( 'wpcf7_is_tel', $result, $text );
}