Contact form 7 kiểm tra số điện thoại VN & Textarea ô lời nhắn, nội dung đúng chuẩn
Bạn sử dụng plugin wordpress contact form 7 để làm form, đôi khi bạn sẽ nhận được email spam như bên dưới. Vậy chúng ta phải làm thế nào để chặn email kiểu này.

Một trong những kiểu email spam
Bạn để ý thường những email spam thường số điện thoại không hợp lệ ở Việt Nam hoặc Textarea ô lời nhắn, nội dung chứa link (URL).
HWP.com.vn dùng phương pháp khi gửi form mình kiểm tra số điện thoại ở Việt Nam chưa? Trong textarea có chứa link a href không.
Mời bạn tham khảo đoạn code bên dưới, chèn vào file functions.php, bước đầu HWP test thử thì mang lại hiệu quả chống email spam.
// kiem tra so dien thoai cua VN (doi so moi nhat)
function custom_filter_wpcf7_is_tel($result, $tel) {
$result = preg_match('/^(0|\+84)(\s|\.)?((3[2-9])|(5[689])|(7[06-9])|(8[1-689])|(9[0-46-9]))(\d)(\s|\.)?(\d{3})(\s|\.)?(\d{3})$/', $tel);
return $result;
}
add_filter('wpcf7_is_tel', 'custom_filter_wpcf7_is_tel', 10, 2);
// kiem tra textarea
function custom_textarea_validation_filter($result, $tag) {
$type = $tag['type'];
$name = $tag['name'];
$value = $_POST[$name];
$Match_all = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
if (preg_match($Match_all, $value)) {
$result->invalidate($tag, "Nội dung gửi không hợp lệ!");
}
return $result;
}
add_filter('wpcf7_validate_textarea', 'custom_textarea_validation_filter', 10, 2);
add_filter('wpcf7_validate_textarea*', 'custom_textarea_validation_filter', 10, 2);

Contact Form 7 kiểm tra số điện thoại