避免在联系表 7 的文本输入中键入数字
Avoid typing numbers in text inputs on contact form 7
我需要一个文本字段,以防止用户在用户写 his/her 名称的地方输入数字,就像默认情况下在根本无法输入字母的数字字段中所做的那样。我正在使用的网站和表格在这里:https://www.recamier.com/muss/club-muss-kids/.
而且我想对 phone 字段做同样的事情,在这种形式中我不得不使用文本字段而不是使用 minlenght:11
maxlength:11
限制。
我找到了解决方案,您必须将此代码粘贴到您的活动主题的 functions.php 文件中。
add_filter( 'wpcf7_validate_text', 'alphanumeric_validation_filter', 20, 2 );
add_filter( 'wpcf7_validate_text*', 'alphanumeric_validation_filter', 20, 2 );
function alphanumeric_validation_filter( $result, $tag ) {
$tag = new WPCF7_Shortcode( $tag );
if ( 'nombre-padre' == $tag->name ) {
$name_of_the_input = isset( $_POST['nombre-padre'] ) ? trim( $_POST['nombre-padre'] ) : '';
if ( !preg_match('/^[a-zA-ZÀ-ÿ ]+$/',$name_of_the_input) ) {
$result->invalidate( $tag, "No se permiten números en este campo" );
}
}
return $result;
}
我在这个页面找到了这个 https://wpquestions.com/Alphanumeric_Validation_Contact_Form_7/19587
我需要一个文本字段,以防止用户在用户写 his/her 名称的地方输入数字,就像默认情况下在根本无法输入字母的数字字段中所做的那样。我正在使用的网站和表格在这里:https://www.recamier.com/muss/club-muss-kids/.
而且我想对 phone 字段做同样的事情,在这种形式中我不得不使用文本字段而不是使用 minlenght:11
maxlength:11
限制。
我找到了解决方案,您必须将此代码粘贴到您的活动主题的 functions.php 文件中。
add_filter( 'wpcf7_validate_text', 'alphanumeric_validation_filter', 20, 2 );
add_filter( 'wpcf7_validate_text*', 'alphanumeric_validation_filter', 20, 2 );
function alphanumeric_validation_filter( $result, $tag ) {
$tag = new WPCF7_Shortcode( $tag );
if ( 'nombre-padre' == $tag->name ) {
$name_of_the_input = isset( $_POST['nombre-padre'] ) ? trim( $_POST['nombre-padre'] ) : '';
if ( !preg_match('/^[a-zA-ZÀ-ÿ ]+$/',$name_of_the_input) ) {
$result->invalidate( $tag, "No se permiten números en este campo" );
}
}
return $result;
}
我在这个页面找到了这个 https://wpquestions.com/Alphanumeric_Validation_Contact_Form_7/19587