验证文本输入字段,仅接受联系人格式为7的字母

问题描述 投票:0回答:1

如何在联系表单7 WordPress插件中使用仅接受字母来验证文本输入字段。

谢谢。

wordpress contact-form-7
1个回答
0
投票
https://contactform7.com/2015/03/28/custom-validation/

类似的东西

add_filter( 'wpcf7_validate_text', 'alpha_validation_filter', 20, 2 ); add_filter( 'wpcf7_validate_text*', 'alph_validation_filter', 20, 2 ); function alph_validation_filter( $result, $tag ) { $tag = new WPCF7_Shortcode( $tag ); if ( 'name-of-the-input' == $tag->name ) { $name_of_the_input = isset( $_POST['name-of-the-input'] ) ? trim( $_POST['name-of-the-input'] ) : ''; if ( !preg_match('/^[a-zA-Z\s]+$/',$name_of_the_input) ) { $result->invalidate( $tag, "Allowed characters are alphanumeric only" ); } } return $result; }

注意:

1。您必须添加在创建字段时添加的输入名称。

© www.soinside.com 2019 - 2024. All rights reserved.