A lot of guests send their phone number or email to the hosts. How can I block automatically phone numbers in messages? in this tutorial it’s only shows block word but not phone numbers How to block or monitor messages - HivePress Help Center
Hi,
Please try this PHP snippet:
add_filter(
'hivepress/v1/forms/message_send/errors',
function($errors, $form){
if(!empty( $errors )){
return $errors;
}
$text = $form->get_value('text');
if(!$text){
return $errors;
}
preg_match_all('/\\+?\\d{1,4}?[-.\\s]?\\(?\\d{1,3}?\\)?[-.\\s]?\\d{1,4}[-.\\s]?\\d{1,4}[-.\\s]?\\d{1,9}$/', $text, $matches);
if(!array_filter($matches)){
return $errors;
}
$errors[] = 'Phone numbers are not allowed in the text';
return $errors;
},
1000,
2
);
If customizations are required for your site, please try customizing it using the collection of code snippets Search · user:hivepress · GitHub and other developer resources, or consider hiring someone for custom work https://fvrr.co/32e7LvY
2 Likes
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.