简体   繁体   English

文本字段联系表7上的自定义验证

[英]Custom Validation on Text Field Contact Form 7

I'm trying to validate a text field that only accepts a valid date eg 21-03-1980 however the validation code is not being triggered but I can't see what is wrong. 我正在尝试验证仅接受有效日期的文本字段,例如21-03-1980,但是验证代码未触发,但我看不到出了什么问题。

Here is the code I am using: 这是我正在使用的代码:

function custom_dob_validation_filter($result,$tag){

    $name = $tag->name;

    if($name == 'datemdy'){

        $datemdy = $_POST['datemdy'];

        if($datemdy != '') {

            if(!preg_match('/^([0-9]{1,2})\\/([0-9]{1,2})\\/([0-9]{4})$/', $datemdy)) {

                $result->invalidate( $tag, "Please Enter a Valid Date of Birth" );

            }

        }

    }

    return $result;
}   

add_filter( 'wpcf7_validate_dob*', 'custom_dob_validation_filter', 10, 2 );
add_filter( 'wpcf7_validate_dob', 'custom_dob_validation_filter', 10, 2 );

Any help would be greatly appreciated. 任何帮助将不胜感激。

TIA TIA

After hours of searching I have found the issue. 经过数小时的搜索,我发现了问题。

add_filter( 'wpcf7_validate_dob*', 'custom_dob_validation_filter', 10, 2 );
add_filter( 'wpcf7_validate_dob', 'custom_dob_validation_filter', 10, 2 );

Should be replaced with: 应替换为:

add_filter( 'wpcf7_validate_text*', 'custom_dob_validation_filter', 10, 2 );
add_filter( 'wpcf7_validate_text', 'custom_dob_validation_filter', 10, 2 );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM