Elixir 验证变更集中的日期格式

Elixir 验证变更集中的日期格式,elixir,phoenix-framework,ecto,Elixir,Phoenix Framework,Ecto,我想在我的变更集中使用此格式验证日期MM/dd/yyyy |> validate_format(:birth_date, ~r/^\d{2}\/\d{2}\/\d{4}$/) field :birth_date, Ecto.Date 但是,我得到了一个错误 ** (FunctionClauseError) no function clause matching in Kernel.=~/2 stacktrace: (elixir) lib/kernel.ex:1580: Ker

我想在我的变更集中使用此格式验证日期
MM/dd/yyyy

|> validate_format(:birth_date, ~r/^\d{2}\/\d{2}\/\d{4}$/)

field :birth_date, Ecto.Date
但是,我得到了一个错误

** (FunctionClauseError) no function clause matching in Kernel.=~/2
 stacktrace:
   (elixir) lib/kernel.ex:1580: Kernel.=~(#Ecto.Date<2010-04-17>, ~r/^\d{2}\/\d{2}\/\d{4}$/)
   (ecto) lib/ecto/changeset.ex:1357: anonymous fn/5 in Ecto.Changeset.validate_format/4
   (ecto) lib/ecto/changeset.ex:1236: Ecto.Changeset.validate_change/3
   test/models/person_test.exs:10: (test)
**(FunctionClauseError)内核中没有匹配的函数子句。=~/2
堆栈跟踪:
(elixir)lib/kernel.ex:1580:kernel.=~(#exto.Date,~r/^\d{2}\/\d{2}\/\d{4}$/)
(exto)lib/exto/changeset.ex:1357:exto.changeset.validate_格式中的匿名fn/5/4
(exto)lib/exto/changeset.ex:1236:exto.changeset.validate_change/3
测试/模型/个人测试。示例:10:(测试)

有什么想法或者这件事不能在一个月内完成吗?谢谢。

日期不是字符串;不能使用正则表达式验证日期。如果您在前面使用的是
cast()
,则应该自动执行此验证以及转换为exto.Date。这不适合你吗?日期不是字符串;不能使用正则表达式验证日期。如果您在前面使用的是
cast()
,则应该自动执行此验证以及转换为exto.Date。这对你不管用吗?