我使用的是contact form 7,我创建了一个文本输入,让用户输入日期。我有占位符mm/dd/yyyy。目前,我正在尝试在该输入中验证此格式。我尝试使用date标记,但在safari上没有,所以这就是我使用text标记的原因。
add_filter('wpcf7_validate_text', 'custom_date_validation', 20, 2);
add_filter('wpcf7_validate_text*', 'custom_date_validation', 20, 2);
function custom_text_validation($result, $tag) {
$type = $tag->type; //object instead of array
$name = $tag->name; //object instead of array
if($name == 'last-name') {
$value = $_POST[$date-signed];
if(!preg_match("^((0|1)\d{1})/((0|1|2)\d{1})/((19|20)\d{2})", $value )){ //new regex statement
$result->invalidate($tag, "Invalid Date");
}
}
return $result;
}
我想当用户没有在输入中输入正确的联系表单7以显示无效的日期。
https://stackoverflow.com/questions/56533750
复制相似问题