diff --git a/lib/pleroma/ecto_type/activity_pub/object_validators/language_code.ex b/lib/pleroma/ecto_type/activity_pub/object_validators/language_code.ex
index 3135af1fa..4779deeb0 100644
--- a/lib/pleroma/ecto_type/activity_pub/object_validators/language_code.ex
+++ b/lib/pleroma/ecto_type/activity_pub/object_validators/language_code.ex
@@ -21,7 +21,7 @@ defmodule Pleroma.EctoType.ActivityPub.ObjectValidators.LanguageCode do
 
   def load(data), do: {:ok, data}
 
-  def good_locale_code?(code) when is_binary(code), do: code =~ ~r<^[a-zA-Z0-9\-]+$>
+  def good_locale_code?(code) when is_binary(code), do: code =~ ~r<^[a-zA-Z0-9\-]+\z$>
 
   def good_locale_code?(_code), do: false
 end
diff --git a/test/pleroma/ecto_type/activity_pub/object_validators/language_code_test.exs b/test/pleroma/ecto_type/activity_pub/object_validators/language_code_test.exs
index 2261cc209..086bb3e97 100644
--- a/test/pleroma/ecto_type/activity_pub/object_validators/language_code_test.exs
+++ b/test/pleroma/ecto_type/activity_pub/object_validators/language_code_test.exs
@@ -20,6 +20,7 @@ defmodule Pleroma.EctoType.ActivityPub.ObjectValidators.LanguageCodeTest do
   test "errors for invalid language code" do
     assert {:error, :invalid_language} = LanguageCode.cast("ru_RU")
     assert {:error, :invalid_language} = LanguageCode.cast(" ")
+    assert {:error, :invalid_language} = LanguageCode.cast("en-US\n")
   end
 
   test "errors for non-text" do