diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php
index 7edfd6d6689..8ef4fb4ede6 100644
--- a/htdocs/core/lib/functions.lib.php
+++ b/htdocs/core/lib/functions.lib.php
@@ -954,12 +954,15 @@ function sanitizeVal($out = '', $check = 'alphanohtml', $filter = null, $options
// Restore entity ' into ' (restricthtml is for html content so we can use html entity)
$out = preg_replace('/'/i', "'", $out);
-
- preg_match_all('/(
getDolGlobalInt("MAIN_SECURITY_MAX_IMG_IN_HTML_CONTENT", 1000)) {
- $out = '';
- }
} while ($oldstringtoclean != $out);
+
+ // Check the limit of external links in a Rich text content. We count '
getDolGlobalInt("MAIN_SECURITY_MAX_IMG_IN_HTML_CONTENT", 1000)) {
+ return 'TooManyLinksIntoHTMLString';
+ }
+
break;
case 'custom':
if (empty($filter)) {